vi Command Reference

(vi stands for VIsual editor, the sucessor to ed, the line mode editor)

Usage: vi [options] filename
Common options: -R   open read only (can also use "view")
                             -r     recover, used if vi exited unexpectedly
                             -x    encryption option (vi will prompt for a password)

There are a whole bunch of other options, see the man pages.
vi has two modes, Command and Input.  The Esc button is used to enter command mode.

A quick ref (the man page is quite long):

Input mode: set insertion point
i insert text at cursor
a append text after cursor
I insert text at beginning of line
A append text at end of line
o open line below cursor
O open line above cursor
Deletion and Change: delete/change words or characters
dw delete a single word
cw change a word
dd delete entire line
R replace line
D delete from cursor position to end of line
C change from cursor position to end of line
x delete a single character
r replace a character
Cursor movement: position the cursor
l move right
h move left
j move down
k move up
$ move to end of line
^ move to beginning of line
w move to next word
e move to end of word
1G move to first line
nG move to line n (where n is a number)
G move to last line
Screen movement: move a screen at a time
ctrl-d scroll forward half a screen
ctrl-u scroll back half a screen
ctrl-f move to next screen
ctrl-b move to previous screen
ctrl-l redraw screen
File usage: file manipulation
:w write buffer
:q quit
:q! force quit without saving
:wq write and quit (save)
:n next file
:r read file
:e edit file
:f file name
:set set options on
:set no set options off
:! escape to shell
:n go to line n
u undo last action
/ search forward
? search back
n repeat search
. repeat last command
yy yank line
p put below cursor
P put above cursor
ZZ write and quit

Copyright © 1993-2001 by Robert Barnes

Return to Unixhub's home page