I like vi, but I'm by no means any sort of guru. I often have to look things up, so here's a nifty reference that I "borrowed" from a good vi introduction.
h move cursor one character to left
j move cursor one line down
k move cursor one line up
l move cursor one character to right
w move cursor one word to right
b move cursor one word to left
0 move cursor to beginning of line
$ move cursor to end of line
nG move cursor to line n
control-f scroll forward one screen
control-b scroll backward one screen
i insert to left of current cursor position (ESC to end)
a append to right of current cursor position (ESC to end)
dw delete current word (ESC to end)
cw change current word (ESC to end)
r change current character
~ change case (upper-, lower-) of current character
dd delete current line
D delete portion of current line to right of the cursor
x delete current character
:g/^$/d delete blank lines containing JUST a carriage return
:g/^ *$/d delete lines with just spaces
ma mark currrent position
d`a delete everything from the marked position to here
`a go back to the marked position
p dump out at current place your last deletion (``paste'')
u undo the last command
. repeat the last command
J combine (``join'') next line with this one
:w write file to disk, stay in vi
:q! quit VI, do not write file to disk,
ZZ write file to disk, quit vi
:r filename read in a copy of the specified file to the current
buffer
/string search forward for string (end with Enter)
?string search backward for string (end with Enter)
n repeat the last search (``next search'')
:s/s1/s2 replace (``substitute'') (the first) s1 in this line by s2
:lrs/s1/s2/g replace all instances of s1 in the line range lr by s2
(lr is of form `a,b', where a and b are either explicit
line numbers, or . (current line) or $ (last line)
EX: :1,10s/up/down/ -- replace up with down on lines 1-10.
:map k s map the key k to a string of vi commands s (see below)
:abb s1 s2 expand the string s1 in append/insert mode to a string
s2 (see below)
% go to the "mate," if one exists, of this parenthesis
or brace or bracket (very useful for programmers!)
:%s/\r/\r/g Replace those pesky CR LF (^M) with an LF
References: