VI (Visual) Editor Command Summary
Inserting Text
a add after cursor
A add to end of line
i insert before cursor
I insert before first nonblank
o open line below cursor
O open line above cursor
Deleting Text
dd delete line
d w delete word
x delete character under cursor
X delete character to left of cursor
D delete rest of line
Undo
u undo last change
U restore current line
Changing and Replacing Text
. repeat last change
r replace character under cursor
R write over text starting at cursor
~ change case
c w change word
J join
split
: 1,$s/X/Y/opt
Global substitute X with Y
options:
g - change every occurrence in line
c - confirm each change
p - print changed lines
Copying and Moving Text
Y yank into buffer
p put buffer after cursor
P put buffer before cursor
Searching Text
/X search forward for X
?X search backward for X
n repeat previous search in the specified direction
N repeat previous search in the opposite direction
: g/pattern/p print every line with pattern in it
Patterns Within Searching
(must use set magic option first)
. any character
* any number of the preceeding pattern
[abc] a, or b, or c
[^abc] any character but a, b, and c
[a-b] any character between a and b
Screen
^ l clear and redraw
File Manipulation
: w name write to file name
: q! quit without saving changes
: wq write and quit
ZZ write and quit
: n edit next file
: n! edit next file, discarding changes to current
: r name read file name into buffer
Options
:set magic allow special search patterns
If a command is preceded with a number it will be repeated that number of times.
EX:
5dd will delete five lines
cancels any command u undo last command