Editing, files, and exiting vi
Keystroke(s)         Meaning
ZZ Save and quit
Q Quit vi and go into ex (bad idea!)
:w Write file
:w! Force write, even if "protected"
:w somefile Write to a new file somefile
:q Quit
:q! Quit, losing all changes
:e somefile Start editing a new file called somefile
:e! Start editing over, forgetting all changes since last save
:n Go to the next file (such as one named on the command line)

 

Movement
Keystroke(s)         Meaning
h, j, k, l The big four: left, down, up, right (←, ↓, ↑, →)
w, W, b, B Forward one word, back one word
e, E end of current word
(, ) Beginning of previous sentence; end of next sentence (doesn't always work correctly!)
{, } Beginning of previous paragraph; end of next pararaph
0, ^ First position, first character
$ End of line
+, - First character of next or previous line
H, M, L Top line of screen, middle line, last line
^F, ^B Forward one screen, back one screen
^D, ^U Down half a screen, up half a screen
z RET Position current line at top of screen
/something Search forward for something
?something Reverse search for something
/ RET Repeat last search forward
? RET Position current line in middle of screen
^G Reports status line (including the current line's number)
^G Reports status line (including the current line's number)
G n RET, :n RET Go to absolute line n
G Go to last line
mx Mark current as x
'x Go to mark x

 

Editing
Keystroke(s)         Meaning
i Insert text
a Append text (very useful at the end of line!)
o, O "Open" a new line immediately below current, "open" a new line immediately above current
r Change one character
cw Change a word from the current point
cc Reinitialize the current line
C Change from current point to end of line
R Overwrite mode
x Delete the current character
dw Delete word
dd Delete current line
D Delete from current character to end of line
p Put back at current
P Put back at previous (much more useful!)
"np Go back in delete history n items for P
yw Copy word (use p,P to retrieve)
yy Copy line (use p,P to retrieve)
"ayy Copy line into buffer a
"aP Paste line from buffer a
:%s/something/otherthing/g Replace something with otherthing throughout the current file
u, U Undo; restore line (very useful!)