vi quick reference guide
The vi editor has two modes: command and insert. The command mode allows the entry of commands to manipulate text. The insert mode puts anything typed on the keyboard into the current file. vi starts out in command mode. There are several commands that put the vi editor into insert mode. The most commonly used commands to get into insert mode are a and i. These two commands are described below. Once you are in insert mode, you get out of it by hitting the escape key. Except where indicated, vi is case sensitive.
Cursor Movement Commands:
(n) indicates a number, and is optional
(n)hleft (n) space(s)
(n)jdown (n) space(s)
(n)kup (n) space(s)
(n)lright (n) space(s)
(The arrow keys usually work also)
^Fforward one screen
^Bback one screen
^Ddown half screen
^Uup half screen
(^ indicates control key; case does not matter)
Hbeginning of top line of screen
Mbeginning of middle line of screen
Lbeginning of last line of screen
Gbeginning of last line of file
(n)Gmove to beginning of line (n)
0(zero) beginning of line
$end of line
(n)wforward (n) word(s)
(n)bback (n) word(s)
eend of word
Inserting Text:
iinsert text before the cursor
aappend text after the cursor (does not overwrite other text)
Iinsert text at the beginning of the line
Aappend text to the end of the line
rreplace the character under the cursor with the next character typed
ROverwrite characters until the end of the line (or until escape is pressed to change command)
o(alpha o) open new line after the current line to type text
O(alpha O) open new line before the current line to type text
Deleting Text:
dddeletes current line
(n)dddeletes (n) line(s)
(n)dwdeletes (n) word(s)
Ddeletes from cursor to end of line
xdeletes current character
(n)xdeletes (n) character(s)
Xdeletes previous character
Change Commands:
(n)ccchanges (n) characters on line(s) until end of the line (or until escape is pressed)
cwchanges characters of word until end of the word (or until escape is pressed)
(n)cwchanges characters of the next (n) words
c$changes text to the end of the line
ct(x)changes text to the letter (x)
Cchanges remaining text on the current line (until stopped by escape key)
~changes the case of the current character
Jjoins the current line and the next line
uundo the last command just done on this line
.repeats last change
ssubstitutes text for current character
Ssubstitutes text for current line
:ssubstitutes new word(s) for old
:<line nos effected> s/old/new/g
&repeats last substitution (:s) command.
(n)yyyanks (n) lines to buffer
y(n)wyanks (n) words to buffer
pputs yanked or deleted text after cursor
Pputs yanked or deleted text before cursor
File Manipulation:
:w (file)writes changes to file (default is current file)
:wq writes changes to current file and quits edit session
:w! (file)overwrites file (default is current file)
:q quits edit session w/no changes made
:q! quits edit session and discards changes
:n edits next file in argument list
:f (name)changes name of current file to (name)
:r (file)reads contents of file into current edit at the current cursor position (insert a file)
:!(command)shell escape
:r!(command)inserts result of shell command at cursor position
ZZwrite changes to current file and exit

(From an Introduction to Unix, University Technology Services, Ohio State University,1996.)