VI Editor
VI Editor
General Startup
To use vi: vi filename
To exit vi and save changes: ZZ or :wq
To exit vi without saving changes: :q!
To enter vi command mode: [esc]
Counts
A number preceding any vi command tells vi to repeat that command that many times.
Cursor Movement
j move down
k move up
xG move to line x
^R redraw screen
^L redraw screen
Inserting
Deleting
yy (yank)'copies' line which may then be put by the p(put) command. Precede with a count for
multiple lines.
Put Command
Find Commands
t find a character on the current line going forward and stop one character before it
T find a character on the current line going backward and stop one character before it
; repeat last f, F, t, T
Miscellaneous Commands
Any commands form the line editor ex can be issued upon entering line mode.
ex Commands
READING FILES
currently editing
:r filename
WRITE FILE
MOVING
:# move to line #
SHELL ESCAPE
:!'cmd'
Invoke vi's edit mode by pressing the Esc key, then a colon ( : ), and enter: 1,$s/oldstring/newstring/g
This will change oldstring into newstring wherever it occurs throughout the entire text. The 1 (the number one) in the
above command means "start the search on the first line". The $ means "end the search on the last line". The g at the
end executes the change globally on each line. If you omit the g , the search will stop after finding the first occurrence of
oldstring.