A long time ago, Maddi Sojourner (nee Hausman) was kind enough to send this to me; now I'm passing it on:
vi Quick Reference
Entering and Leaving vi File Manipulation
% vi name edit name at top :w write back changes
% vi +n name ...at line n :wq write and quit
% vi + name ...at end :q quit, discard changes
% vi r list saved files :e name edit file name
% vi -r name recover file name :e! reedit, discard changes
% vi name ... edit first, rest via :u :e + name edit, at end
% vi -t tag start at tag :e +n edit, at line n
% vi +/pat name search for pat :e # edit alternate file
% view name read-only mode Ctrl-^ synonym for :e #
ZZ exit vi, save changes :r name read file name
Ctrl-Z stop vi for later :w name write file name
resumption :w! name overwrite file name
:w>> name append to file name
:sh run shell, return
The Display :!cmd run cmd, return
Last Line Error msgs, echoing :n edit next file in
input to : / ? !, arglist
feedback on i/o, :n args specify new arglist
and large changes :f show current file, line
@ lines On screen, not file Ctrl-G synonym for :f
~ lines Lines past eof :ta tag to tag file entry tag
Ctrl-x Ctrl chars, DEL=delete Ctrl-] :ta, following word=tag
tabs Expand to spaces,
cursor at last Positioning within File
Ctrl-F forward screenful
Vi Modes Ctrl-B backward screenful
Command Normal & initial state. Ctrl-D scroll down half screen
Others return here. Ctrl-U scroll up half screen
ESC cancels partial G goto line (default=end)
command. /pat next line matching pat
Insert Entered by a i A I o O ?pat same, search backwards
c C s S R. Text ends n repeat last / or ?
with ESC or abnormal N reverse last / or ?
interrupt /pat/+n nth line after pat
Last Line Reading input for : / ?pat? -n nth line before pat
? or !; end with ESC ]] next section/function
or CR to execute, [[ previous section/funct
interrupt to cancel % find matching (),{},[]
Counts Before vi Commands Adjusting the Screen
line/column number z G | Ctrl-L clear and redraw
scroll amount Ctrl-D, Ctrl-U Ctrl-R retype, w/o @ lines
replicate a i A I zCR redraw at window top
repeat effect most of the rest z- ...at bottom
z. ...at center
Simple Commands /pat/z- pat line at bottom
dw delete word xn, use n line window
de ...leaving punctuatn Ctrl-E scroll window down
dd delete line 1 line
3dd ...3 lines Ctrl-Y scroll window up 1 line
iabcESC insert text abc
cwnewESC change word to new Interrupting, Cancelling
casESC pluralize word ESC end insert or incomplete cmd
xp transpose characters Ctrl-C interrupt (DEL)
Ctrl-L refresh screen if scrambled
Marking & Returning
`` Previous context Corrections During Insert
'' ...at first non-white Ctrl-H erase last character
in line Ctrl-W erases last word
mx mark position with letter x erase your erase, as Ctrl-H
`x to mark x kill your kill, erase line input
'x ...at first non-white in line \ escapes Ctrl-H, erase, kill
Ctrl-C interrupt, terminates insert
Line Positioning Ctrl-D backtab over autoindent
H home window line Ctrl-^D kill autoindent, save for next
L last window line 0Ctrl-D ...but at margin next also
M middle window line Ctrl-V quote non-printing character
+ next line, at first non-white
- ...same, but at previous line Insert & Replace
CR return, same as + a append after cursor
j next line, same column i insert before cursor
k previous line, same column A append to end of line
I insert before first non-blank
Character Positioning o open line below
^ first non-blank O open line above
0 beginning of line rx replace single character with x
$ end of line R replace characters
l forward one character
h backward one character Operators (double to affect lines)
Ctrl-H same as h d delete
space same as l c change
fx find x forward < left shift
Fx find x backward > right shift
tx up to x forward ! filter through command
Tx back up to x = indent for LISP
; repeat last f F t T y yank lines to buffer
, inverse of ;
| to specified column Miscellaneous Operations
% find matching ( { [ ) } ] C change rest of line
D delete rest of line
Words, Sentences, Paragraphs s substitute character
w word forward S substitute lines
b word backward J join lines
e end of word x delete characters
) to next sentence X ...before cursor
} to next paragraph Y yank lines
( back sentence
} back paragraph Yank & Put
W blank delimited word p put back lines
B back W P put before
E to end of W "xp put from buffer x
"xy yank to buffer x
Commands for LISP "xd delete into buffer x
) forward s-expression
} ...but don't stop at atoms Undo, Redo, Retrieve
( back s-expression u undo last change
{ ...but don't stop at atoms U restore current line
. repeat last change
"dp retrieve dth last delete