linux and unix vi editor commands




Vi Editor Commands
vi f1 initiates an edit session on the file f1.
vi -r f1 initiates an edit session on a recovered
version of the file f1.
ZZ will write the changes into the file and exit.
:q! will exit and discard the changes.
:w will update the file being edited without exiting.
:wq same as ZZ.
ENTER INSERT MODE
a appends text after the cursor position.
A Appends text at the end of the current line.
i inserts text before the cursor postion.
I Inserts text at the beginning of the current line.
o opens a new line below the cursor postion.
O Opens a new line above the cursor postion.
R Replaces the existing text on a line. End with .
s substitutes entered text for the character under the
cursor.
EXIT INSERT MODE
type escape to re-enter command mode.
COMMAND MODE
Cursor movement
h moves the cursor one character to the left.
j moves the cursor one line down in the file.
k moves the cursor one line up in the file.
l moves the cursor one character to the right.
+ moves cursor to the beginning of the next line.
– moves cursor to the beginning of the previous line.
$ moves the cursor to the end of the current line.
0 (zero) moves the cursor to the first character in the line.
^F moves the display forward a full terminal page.
^B moves the display back a full terminal page.
^D scrolls down one half terminal page.
^U scrolls up one half terminal page.
W or w moves the cursor forward one “word”.
5W moves the cursor forward 5 “words”.
E or e moves the cursor to the end of the current word.
B or b moves the cursor back one “word”.
G moves the cursor to the last line in the file.
10G moves the cursor to line 10.
Text moving commands
yy Yank a copy of a line, place it in a buffer.
10yy Yank 10 lines and place them in a buffer.
p put the last item yanked after the cursor.
P Put the last item yanked before the cursor.
“cY Yank a copy of a line, place it into buffer c.
“cP Put the contents of buffer c before the cursor.
Other commands
^L redraws the screen.
x deletes the character under the cursor.
dd deletes the current line.
dw deletes the current word.
4dw deletes 4 words.
D deletes from the cursor position to the end
of the current line.
r replaces the character under the cursor.
u undoes the last command that changed the buffer.
U undoes changes to the current line.
cw changes from the cursor to the end of the word..
cc changes the current line.
C changes from the cursor to the end of the line..
/string Searches for “string”.
n finds the next occurrence of an established “string”.
N finds the previous occurrence of an established
“string”.
:s/walk/talk/ substitute “talk” for the first “walk” on the
current line.
:1,8s/aa/bb/g substitutes “bb” for each “aa” in lines 1 to 8.
:3,9w x writes lines 3 through 9 to the file x.
:r x read the file x in after the current line.
:set all reports on the settings of the current edit options.
:set ai sets the auto-indent option for programming.