vi Commands

Notation

Things in Italics represent variable text.
Things in bold represent special keys. Control keys are indicated by CTRL-key (for example CTRL-w), the escape key by ESC, and the (carriage) return key by CR.

Absolute Minimum

vi filenamebegin vi
ZZsave and exit vi
arrow keysmove in direction of arrow
backspace (or delete)delete previous character
ienter insert mode (start typing text)
ESCleave insert mode (this puts you in command mode)

Most Useful

h, j, k, l move left, down, up, and right respectively
wmove to start of next word in current line
bmove to start of previous word in current line
0 (zero)move to beginning of current line
$move to end of current line
27Gmove to line 27
Gmove to the last line in the file
CTRL-dscroll down one screenful
CTRL-uscroll up one screenful
CTRL-wdelete previous word
xdelete current character
dwdelete next word
dbdelete previous word
dddelete current line
uundo last command

Others

:wsave but do not exit
:q!quit without saving
ndelete commands can be preceded by a number
for example 3dw deletes the next three words

Cut and Paste

ycmd copy from current location to location given by cmd
for example y3w will copy three words
yycopy the current line
ppaste (after cursor)

Searching

/textCR search forward for text
nfind next occurrence of text matching most recent search
?textCRsearch backward for text

Special Matches

.matches any character
/<matches beginning of word
\>matches end of word
[str]matches any character in str
for example, [ahx] matches a, h, or x
[a-z] matches any character in the range
for example, [a-c] matches a, b, or c
*matches zero or more occurances of the previous character
for example a* will match a, aa, aaa, etc.
\is the escape character
for example, use \* to search for *