VI REFERENCE

<n>		number or repeat n times
<r>		range: n; n,m; %
<m>		motion: $, 0, [hlkj], `c, etc.
<CR>		ENTER

FILE COMMANDS

vi [file...]	edit a file or files
vi -r file	retrieve saved file after crash
:wq		save and exit
:x, ZZ		conditionally save, and exit
:q, :q!		quit; quit without saving
:w [file]	save file (as file)
:e file		edit filename
:e!		revert to file on disk
:r file		insert contents of file
:sh		drop to shell
:! cmd		run command cmd
:<r>! cmd	filter range through cmd
:r !cmd		execute cmd and insert output

MOVING AROUND

<n>G		line number n
<n>|		column n of line
H, M, L		top, middle, bottom line of screen
h, l, k, j	left, right, up, down one character
b, B		previous (non-blank) word
w, W		next (non-blank) word
0, $		beginning of line, end of line
^		first non-blank chacter of line
G		end of file
e, E		end of current word (non-blank)
), (		beginning of (next, previous) sentence
}, {		beginning of (next, previous) paragraph
]], [[		beginning of (next, previous) section
%		matching brace
^B, ^F		back, forward one screen
^U, ^D		back, forward one-half screen
^E, ^Y		show one more line at (top, bottom)
		of screen
z<CR>, z., z-	repos. screen with cursor at
		(top, mid, bottom)

MARKING

mc		create a mark called c
`c		return to c
``		return to previous position

VI REFERENCE (cont'd)

SEARCH

/txt, ?txt	search (backward) for text (regex)
*, #		search (backward) for word under cursor
n, N		repeat last search (in opposite direction)
fc, Fc		search (backward) for character c in line
tc, Tc		search (backward) to character before c in
		line
;, ,		repeat line search (in opposite direction)

INSERT/REPLACING TEXT

s, S		substitute: delete (char., line) and insert
		text
i, a		insert text (before, after) cursor
I, A		insert text (before beginning, after end)
		of line
r, R		replace (character, to end of line)
c<m>, cc	change from cursor to motion, change line
C, c$		change from cursor to end of line
o, O		open new line for text (below, above) cursor

MODIFING TEXT

:>, :<		indent, outdent line
:> n		indent n lines
J		join current line and next
~		swap character's case

CUT/COPY/PASTE

d<m>, dd	delete from cursor to motion, delete line
D, d$		delete to end of line
x, X		delete character forward; backward
<n>yy, <n>Y	copy n lines
y<m>, yy	copy to motion; line
p, P		paste text after; before cursor

MISC

u, .		undo, repeat last change
xp		transpose characters
ddp		transpose lines
^L		redraw screen
:[%]s/a/b/[gc]	replace a with b
		% - to end of file
		g - all occurances in line
		c - confirm changes