General Startup

To use vi: vi filename
To exit & save changes: ZZ or :wq
To exit without saving changes: :q!
To save the current file without quitting: :w
To copy (read) filename after cursor in file currently editing: :r filename
To enter vi command mode: [esc]

Line Editor Mode

Any commands form the line editor can be issued upon entering line mode.

To enter: type ':'
To exit: press [return] or [esc]

Screen Movement

Gmove to the last line in the file
xGmove to line x
z+move current line to top of screen
zmove current line to the middle of screen
z-move current line to the bottom of screen
^Fmove forward one screen
^Bmove backward one line
^Dmove forward one half screen
^Umove backward one half screen
^Rredraw screen ( does not work with VT100 type terminals )
^Lredraw screen ( does not work with Televideo terminals )

Shell Escape

executes 'cmd' as a shell command:
:!cmd

Copying Code

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

Find Commands

?finds a word going backwards
/finds a word going forwards
ffinds a character on the line under the cursor going forward
Ffinds a character on the line under the cursor going backwards
tfind a character on the current line going forward and stop one character before it
Tfind a character on the current line going backward and stop one character before it
;repeat last f, F, t, T


:%s/regex/repl/flags replace

Moving

:# move to line #
:$ move to last line of file

Miscellaneous Commands

.repeat last command
uundoes last command issued
Uundoes all commands on one line
xpdeletes first character and inserts after second (swap)
Jjoin current line with the next line
^Gdisplay current line number
%if at one parenthesis, will jump to its mate
mxmark current line with character x
'xfind line marked with character x


NOTE

: Marks are internal and not written to the file.

Put Command

brings back previous deletion or yank of lines, words, or characters

Pbring back before cursor
pbring back after cursor

Cursor Movement

hmove left (backspace)
jmove down
kmove up
lmove right (spacebar)
[return]move to the beginning of the next line
$last column on the current line
0move cursor to the first column on the current line
^move cursor to first nonblank column on the current line
wmove to the beginning of the next word or punctuation mark
Wmove past the next space
bmove to the beginning of the previous word or punctuation mark
Bmove to the beginning of the previous word, ignores punctuation
eend of next word or punctuation mark
Eend of next word, ignoring punctuation
Hmove cursor to the top of the screen
Mmove cursor to the middle of the screen
Lmove cursor to the bottom of the screen

Inserting

rreplace character under cursor with next character typed
Rkeep replacing character until [esc] is hit
iinsert before cursor
aappend after cursor
Aappend at end of line
Oopen line above cursor and enter append mode

Deleting

xdelete character under cursor
dddelete line under cursor
dwdelete word under cursor
dbdelete word before cursor

Counts

A number preceding any vi command tells vi to repeat that command many times.