Colorado School of MinesCSM Academic Computing and Networking Academic Computing and Networking Home About Us Contact Us CSM Home Services Getting Help Guides and Reference Documents FAQfinder Search
   

VI Editor Quick Reference


Entering vi
 

vitutor invokes a tutorial for vi
vi filename enter vi to edit a file

Saving and Exiting
 
ZZ Quit and save :q! Quit and ignore edit changes
:wq Quit and save :w Save changes and stay in file

Positioning the Cursor in Text
 
G Go to the last line in the file e End of the current word
nG Go to line number n ( Beginning of the previous sentence
:n Go to line number n ) Beginning of the next sentence
b Back one word { Beginning of the previous paragraph
w Start of next word } Beginning of the next paragraph
 
Moving/Scrolling
 
H Home-top line on screen ^F Scroll forward one screen
M Middle line on screen 0 (zero) Go to first position on current line
L Last line on screen $ Go to last position on current line
^B Scroll back one screen k Move up one line
^U Scroll back half screen h Move left one character
^ Go to first position on current line j Move down one line
^D Scroll forward half screen l Move right one character

Inserting New Text
 
i Insert before cursor o Insert one line below cursor
I Insert at beginning of line O Insert one line above cursor
a Appends text after cursor position J Joins current line with following line
A Appends text to end of line Esc Terminate insert mode
 
Deleting and Copying Text
 
x Delete single character at current cursor position ndd Delete n lines
dw Delete a word ndw Delete n words
dd Delete a current line Y or yy Copy current line to new location
d0 (zero) Delete back to the beginning of a line p Place last deleted text after cursor
D Delete remainder of line P Place last deleted text before cursor

Changing Text
 
rx Replace a character with x cw Change word
R Replace beginning at cursor location cc Change line
c0 Change to beginning of line C Change to end of line

Searching
 
/string Search forward for string
?string Search backward for string
:s/old/new/n Search and replace n times

Miscellaneous Commands
 
:!command Issue UNIX command from within vi . Repeat the last command
:r file Append file into vi u Undo the last command
:f file Change current filename to file z Redraw the screen

 

Questions and comments -- open a ticket at the Mines Help Center
Thursday, 13-Sep-2007 09:48:16 MDT