VI Quick Reference

Movement Commands
Character Movement
h or <left arrow> or Ctrl-H
l or <right arrow> or <Space>
k or <up arrow> or Ctrl-P
j or <down arrow> or Ctrl-N or Ctrl-J
one character to the left
one character to the right
one character up
one character down
Text
b, w
B, W
e, E
( , )
{ , }
backward, forward one regular word
backword, forward one blank delimited word
forward to end of regular/blank delimited word
beginning of previous, next sentence
beginning of previous, next paragraph
Lines
0, $
^
-, +
|
n|
H, M, L
nH
nL
G
nG
:n<Enter>
first, last position of current line
first nonblank character of current line
first character of previous, next line
move to column 1 of current line
move to column n of current line
top, middle, bottom line of screen
n lines after top line
n lines before bottom line
move to last line in file
move to line n
move to line n
Screens
Ctrl-B, Ctrl-F
Ctrl-U, Ctrl-D
Ctrl-Y, Ctrl-E
z <Enter>
z.
z-
Scroll backward, forward one screen
Scroll up, down one half screen
Show one more line at top, bottom of screen
Reposition line with cursor to top of screen
Reposition line with cursor to middle of screen
Reposition line with cursor to bottom of screen
Marking Position
mx
'x
`x
'' (two single quotes)
``
Mark current position as x
Move to first character of line with mark x
Move to character at mark x
Move to previous position
Move to beginning of line with previous position
Searches
fx
Fx
tx
Tx
;
,
/pattern <Enter>
?pattern <Enter>
n, N
/, ?
Search forward in current line for character x
Search backward in current line for character x
Search forward in current line for character before character x
Search backward in current line for character after character x
Repeat last f, F, t, T in same direction
Repeat last f, F, t, T in opposite direction
Search forward for pattern
Search backward for pattern
Repeat last search in same, opposite direction
Repeat last search in forward, backward direction
Moving to Matching Delimiter
%
Move to matching (, ), [, ], {, }


Editing Commands
Inserting Text
i, a
I, A
o, O
Insert text before, after cursor
Insert text at beginning, end of current line
Open new line after, before current line
Changing Text
r
~
s
S
C
R
cc
cw
cW
cb
cB
ce
cE
c)
c(
c}
c{
c0
c$
c^
cH
cM
c'x
c/pattern
cL
Replace with next typed character
Change case of character
Delete character and enter input mode
Delete current line and enter input mode
Delete to end of line and enter input mode
Overwrite text starting with current character
Delete current line and enter input mode
Replace next regular word and enter input mode
Replace next blank delimited word and enter input mode
Delete to beginning of regular word and enter input mode
Delete to beginning of blank delimited word and enter input mode
Same as cw
Same as cW
Delete to beginning of next sentence and enter input mode
Delete to beginning of sentence and enter input mode
Delete to beginning of next paragraph and enter input mode
Delete to beginning of paragraph and enter input mode
Delete to beginning of line and enter input mode
Delete to end of line and enter input mode
Delete to first non blank in line and enter input mode
Delete to top line of screen and enter input mode
Delete to middle line of screen and enter input mode
Delete to position x and enter input mode
Delete to next occurrence of pattern and enter input mode
Delete to last line of screen and enter input mode
Note: All possible change commands were not listed.
Deleting Text
x
X
dd
D
dw
db
dB
de
dE
d)
d(
d}
d{
d0
d$
d^
dH
dM
d'x
d/pattern
dL
Delete character
Delete character before cursor
Delete current line
Delete to end of line
Delete next regular word
Delete next blank delimited word
Delete to beginning of regular word
Delete to beginning of blank delimited word
Same as dw
Same as dW
Delete to beginning of next sentence
Delete to beginning of sentence
Delete to beginning of next paragraph
Delete to beginning of paragraph
Delete to beginning of line
Delete to first nonblank in line
Delete to top of screen
Delete to middle line of screen
Delete to position x
Delete to next occurrence of pattern
Delete to last line of screen
Note: All possible delete commands were not listed.
Cutting and Pasting Text (Yanking and Putting)
Y
yy
p
P
Yw
YW
Yb
YB
Ye
YE
Y)
Y(
Y}
Y{
Y0
Y$
Y^
YH
YM
Y'x
Y/pattern
YL
Yank current line
Yank current line
Put yanked (deleted) text after cursor
Put yanked (deleted) text before cursor
Yank next regular word
Yank next blank delimited word
Yank to beginning of regular word
Yank to beginning of blank delimited word
Same as Yw
Same as YW
Yank to beginning of next sentence
Yank to beginning of sentence
Yank to beginning of next paragraph
Yank to beginning of paragraph
Yank to beginning of line
Yank to end of line
Yank to first nonblank in line
Yank to top line of screen
Yank to middle line of screen
Yank to position x
Yank to next occurrence of pattern
Yank to last line of screen and enter input mode
Note: p and P can also be used to paste (put) deleted text.
Note: All possible Yank commands were not listed.
Exit Commands
ZZ
:x
:wq
:w
:q
:q!
:n,mw newfile
:n,mw>>file
:e!
Save file and exit
Save file and exit
Save file and exit
Save file
Exit (if no changes)
Exit (even if changes)
Save lines n as m to newfile
Append lines n through m to file
Return file to last saved version
Other
Ctrl-G
.
u
U
J
:!cmd
:rfilename
:r!cmd
:set option
:set option=value
:set
:set all
:set option?
Display current line number
Repeat last edit command
undo last edit
Restore current line
Join current line and follow line
Execute Unix command cmd
Read contents of filename into current file
Read output of Unix command cmd into file
Activate option
Assign value to option
Display options set by user
Display all current options
Display setting of option


Alphabetical List of Keys
a
A
Ctrl-A
Insert text after cursor position
Insert text at end of line
not used
b
B
Ctrl-B
Move to beginning of regular word
Move to beginning of blank delimited word
Scroll Back on screen
c
C
Ctrl-C
Change text
Change to end of line
not used
d
D
Ctrl-D
Delete text
Delete to end of line
Scroll down half a screen
e
E
Ctrl-E
Move to end of regular word
Move to end of blank delimited word
Show one more line at bottom of screen
fx
Fx
Ctrl-F
Find next x in current line
Find previous x in current line
Scroll forward one screen
g
G
Ctrl-G
not used
Go to last line in file (or specified line)
Display current line number
h
H
Ctrl-H
Move cursor one character left
Move cursor to beginning of top line of screen
Move cursor one character left (deletes text in input mode)
i
I
Ctrl-I
Insert text before cursor
Insert text at beginning of line
not used
j
J
Ctrl-J
Move cursor down one line
Join two lines
Move cursor down one line
k
K
Ctrl-K
Move cursor up one line
not used
not used
l
L
Ctrl-L
Move cursor right one character
Move cursor to last line on screen
Redraw screen
mx
M
Ctrl-M
Mark the cursor position as x
Move cursor to line in middle of screen
Move cursor to beginning of next line
n
N
Ctrl-N
Repeat last search command
Repeat last search command in opposite direction
Move cursor down one row
o
O
Ctrl-O
Add a line after current line and enter input mode
Add a line before current line and enter input mode
not used
p
P
Ctrl-P
Put yanked or deleted text after cursor
Put yanked or deleted text before text
Move cursor up one line
q
Q
Ctrl-Q
not used
Quit vi and start ex
not used in command mode; in insert mode quotes next character
r
R
Ctrl-R
Replace character with next character typed
Replace characters
Redraw Screen
s
S
Ctrl-S
Change the character at cursor position
Change entire line
not used
tx
Tx
Ctrl-T
Find character before next x in current line
Find character after previous x in current line
not used
u
U
Ctrl-U
Undo last change made
Restore current line discarding changes to it
Scroll up one half screen
v
V
Ctrl-V
not used
not used
not used in command mode; in insert mode quotes next character
w
W
Ctrl-W
Move to beginning of next regular word
Move to beginning of next blank delimited word
not used in command mode; in insert mode, backs up one word
x
X
Ctrl-X
Delete character at cursor
Delete character before cursor
not used
y
Y
Ctrl-Y
Yank text
Yank current line
Show one more line at top of screen
z
Z
Ctrl-Z
Reposition current line
not used (ZZ saves file and exits)
not used

Furnished by the Mainframe/Minicomputer Team of Academic Computing