- Starting Vi
-
edit an empty buffer: vi
-
edit a file: vi filename
- Leaving Vi
-
write buffer to file: :w
-
write buffer to file filename: :w
filename
-
quit: :q
-
quit discarding changes: :q!
-
write changes and quit: :wq
-
write changes and quit: ZZ
- Special Notes
Use the escape key, <esc>,
to leave insert mode or to cancel an incomplete command.
If a command doesn't work, try hitting <esc>
and entering the command again.
- Motion commands
-
move up one line: k
-
move down one line: j
-
move left one character: h
-
move right one character: l
-
scroll up one line: <ctrl>y
-
scroll down one line: <ctrl>e
-
scroll up (default is a half page):
<ctrl>u
-
scroll down (default is a half page):
<ctrl>d
-
show next page page: <ctrl>f
-
show previous page page: <ctrl>b
-
move to beginning of next line: +
-
move to beginning of previous line: -
-
move to beginning of first screen line: H
-
move to middle line of screen: M
-
move to last line of screen: L
-
move to the nth line: nG
-
move to the nth line: :n
-
move to the next occurrence of c on the current line:
fc
-
move to the character in front of the next occurrence of c on the
current line: tc
-
move forward to the next word: w
-
move forward to the end of the next word: e
-
move backward to the previous word: b
All commands except M, nG, and :n
can be preceeded by an integer to indicate the distance to
move.
- Text entering commands
-
append text at end of line: A
-
append text after cursor: a
-
insert text at beginning of line: I
-
insert text before cursor: i
-
open a new line above cursor: O
-
open a new line below cursor: o
All commands must be terminated with an
<esc> after the text has been entered.
- Text deletion commands
-
delete character left of cursor: X
-
delete character under cursor: x
-
delete rest of word: dw
-
delete rest of sentence: d)
-
delete rest of paragraph: d}
-
delete to beginning of current line: d^
-
delete to end of current line: d$
-
delete to end of current line: D
-
delete line containing cursor: dd
-
delete the current line upto and including c: dfc
-
delete the current line upto c: dtc
All commands can be preceeded by an integer to indicate the number of
characters, words, lines etc. to be deleted.
- Text alteration commands
-
replace text: R
-
replace character with c: rc
-
transpose two characters: xp
-
join the next line to the end of the current line:
J
-
undo last change: u
-
undo last change to current line: U
-
change rest of word: cw
-
change rest of sentence: c)
-
change rest of paragraph: c}
The commands R,
cw,
c) and c} must be terminated with an <esc> after the new text has been
entered. All commands, except xp,
u, and U can be preceeded by an integer to
indicate the amount of alteration to perform.
- Text moving commands
-
yank a copy of the current line and place it in a buffer: yy
-
put the last item yanked or deleted before the cursor: P
-
put the last item yanked or deleted after the cursor: p
-
yank a copy of the current line and place it in buffer c:
"cY