[Next] [Previous] [Up] [Top] [Contents]

CHAPTER 10 Editors

10.3 vi Quick Reference Guide


All commands in vi are preceded by pressing the escape key. Each time a different command is to be entered, the escape key needs to be used. Except where indicated, vi is case sensitive.
 
Cursor Movement Commands:
(n) indicates a number, and is optional
(n)hleft (n) space(s)
(n)jdown (n) space(s)
(n)kup (n) space(s)
(n)lright (n) space(s)
(The arrow keys usually work also)
^Fforward one screen
^Bback one screen
^Ddown half screen
^Uup half screen
(^ indicates control key; case does not matter)
Hbeginning of top line of screen
Mbeginning of middle line of screen
Lbeginning of last line of screen
Gbeginning of last line of file
(n)Gmove to beginning of line (n)
0(zero) beginning of line
$end of line
(n)wforward (n) word(s)
(n)bback (n) word(s)
eend of word
   
   
Inserting Text:
iinsert text before the cursor
aappend text after the cursor (does not overwrite other text)
Iinsert text at the beginning of the line
Aappend text to the end of the line
rreplace the character under the cursor with the next character typed
ROverwrite characters until the end of the line (or until escape is pressed to change command)
o(alpha o) open new line after the current line to type text
O(alpha O) open new line before the current line to type text
Deleting Text:
dddeletes current line
(n)dddeletes (n) line(s)
(n)dwdeletes (n) word(s)
Ddeletes from cursor to end of line
xdeletes current character
(n)xdeletes (n) character(s)
Xdeletes previous character
Change Commands:
(n)ccchanges (n) characters on line(s) until end of the line (or until escape is pressed)
cwchanges characters of word until end of the word (or until escape is pressed)
(n)cwchanges characters of the next (n) words
c$changes text to the end of the line
ct(x)changes text to the letter (x)
Cchanges remaining text on the current line (until stopped by escape key)
~changes the case of the current character
Jjoins the current line and the next line
uundo the last command just done on this line
.repeats last change
ssubstitutes text for current character
Ssubstitutes text for current line
:ssubstitutes new word(s) for old
:<line nos effected> s/old/new/g
&repeats last substitution (:s) command.
(n)yyyanks (n) lines to buffer
y(n)wyanks (n) words to buffer
pputs yanked or deleted text after cursor
Pputs yanked or deleted text before cursor
File Manipulation:
:w (file)writes changes to file (default is current file)
:wq writes changes to current file and quits edit session
:w! (file)overwrites file (default is current file)
:q quits edit session w/no changes made
:q! quits edit session and discards changes
:n edits next file in argument list
:f (name)changes name of current file to (name)
:r (file)reads contents of file into current edit at the current cursor position (insert a file)
:!(command)shell escape
:r!(command)inserts result of shell command at cursor position
ZZwrite changes to current file and exit


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]