vi


Download the VI Cheat Sheet at http://www.kcomputing.com/vi.html


Open, Save and Quit

to use VI: vi filename
to enter vi command mode: [esc]
to exit vi and save changes: :wq
to save only: :w
to quit only without saving changes: :q!


Add text commands

insert here: insert or i
insert at start of line: I
append here: a
append at end of line: A
replace: R
open line above cursor and enter append mode: O


Cursor Movement Commands

go to line 1: 1G
go to line 76: 76G
go to end of file: G
move ahead 5 words: 5W
move up 16 lines: 16K
end of line: $
beginning of line: ^ (non blank) or 0 (blank)
go to previous character: h
go to previous word: b
go to next character: l
go to next word: w
end of next word: e
move past the next space: W
go one line up: k or arrow_up
go one line down: j or arrow down
move to top of the screen: H
move to middle of the screen: M
move to the bottom of the screen: L


Changing Commands

delete current line: dd
delete one character: delete or x
delete 5 words: d5w
delete till end of file: dG
delete word under cursor: dw
delete word before cursor: db
undo last change: u
restore line: U
change to end of line: c$


Copy

yy    (yank) 'copies' line which may then be put by the p (put) command. Precede with a count for multiple lines.
p     bring back after cursor
P     bring back before cursor


Find

?    finds a word going backwards
/    finds a word going forwards
f    finds a character on the line unter the cursor going forward
F    finds a character on the line unter the cursor going backwards
t    find a character forward on the current line
T    find a character backward on the current line
;    repeat last f, F, t, T


Miscellaneous Commands

.    repeat last command
J    join current line with the next line


a number preceding any vi command tells vi to repeat that command that times.