Tutorial
Vim (vi Improved)
Basics
Overview
vim
(vi improved) is a upgraded version of vi
, the standard editor of Uinx, and which is now avaialable on all platforms you're likely to
encounter.
- vim is a modal editor; this means that there are several ways (modes) of interacting with the editor.
- three basic modes are:
- normal mode - basic navigation/editing - nothing or file name on status line
- insert mode - text insertion -
-INSERT-
on status line
- command mode - more involved commands: saving, searching, moving, etc., -
:
on status line
- Also known as EX-mode (after the editor this mode is based on)
- Pressing the
Esc
key will always return you to normal mode.
- Reasons for having multiple modes:
- Terminals when vi was introduced did not have mice or dedicated function keys; having an insert mode and a normal mode allowed the
available keys to serve double duty.
- In a related vein, using the standard typewriter keys to act as command and navigation keys (in normal mode) allowed a touch typist to
efficiently edit without their hands having to leave the home row (compare that with your editorm where you're constantly
moving off the main keyboard to use the mouse or the arrow or other special-purpose keys).
Normal Mode
- Basic navigation:
h, j, k, l
- left, down, up, and right one char respectively; the arrow keys will work as well
w, b
- forward / backward one word respectively
f, F
- followed by a char - move cursor forward/backward onto the specified character
t, T
- followed by a char - move cursor forward/backward to charcater before/after the specified character
- Basic editing:
x
- delete the character beneath the cursor
- Entering insert mode:
i, a
- enters insert mode before/after the current cursor position.
a
(for append) is necessary when you are trying to add text at the end of the line)
Insert Mode
- Arrow keys may work (i.e., you may be able to use them without having to go back to normal mode)
- Again, use the
Esc
to return to normal mode
Command Mode
- Entered from normal mode via
:
(colon)
w
- write (save) the currently edited file
q
- quit (exit) vi
- above two can be combined to
wq