VI Editor Quick Reference

[Copyright 1984,2000,2001,2002,2016 Frank Durda IV, All Rights Reserved.
Mirroring of any material on this site in any form is expressly prohibited.
The official web site for this material is:  http://nemesis.lonestar.org
Contact this address for use clearances: clearance at nemesis.lonestar.org
Comments and queries to this address: web_reference at nemesis.lonestar.org]

The VI editor is an extremely powerful editor with hundreds of commands and options. The mere presence of this number of commands and options can make VI an intimidating editor to use. However, for most people used to working with the primitive mouse-driven editors that are omni-present today, remembering and using just a handful of vi commands will allow you to out-edit all of those other editors. The fundamental vi commands you need to know are shown below.


VI One column command reference

This version was originally produced to be used as a bookmark
or be narrow enough to tape to the side of a monitor.

All of the commands shown are issued in Command Mode.
While in Insert Mode, all characters typed except [ESC]
become part of the file.

[ESC] exits Insert mode and goes to Command mode. Also aborts incomplete commands.
i Enters Insert mode. subsequent text is added in front of the cursor. Use [ESC] to get back to Command mode.
a Enters Insert mode and adds new text on right of cursor.
A Enters Insert mode and adds new text to end of line.
o Inserts a blank line below cursor and goes into Insert mode.
O Same as o, but opens line above cursor.
d[SPACE] Deletes one character.
dw Deletes up to next word.
de Deletes up to end of current word.
d0 Deletes from cursor to start of line.
dd Deletes entire line.
dnG Deletes a range of lines. d1G deletes from the current line to the first line of the file. dG deletes from the current line to the end of the file. If the cursor is on line 3, d6G deletes lines 3 through 6.
D Deletes from cursor to end of current line.
x Also deletes one character.
u Undoes last operation (insert, delete, substitute, etc.) Additional consecutive u commands either undoes the undo or undoes previous operations (action depends on the version of vi used).
[LEFTARROW] or h Back up one space.
[DOWNARROW] or j Move down one line.
[UPARROW] or k Move up one line.
[RIGHTARROW] or l Move to the right.
[n] All movement and delete keys can be preceded by a number to repeat the operation, ie, 12j moves 12 lines down.
[n]G Moves to line n. If the number is omitted, move to last line.
/text Looks for next occurrence of text. Omitting text searches for previous string. ?text searches towards start of file.
:%s/find/change/[g] Replace find with change in next occurrence. Adding 'g' to end of command changes all occurrences.
:se [no]modecommand Control things like case sensitivity in searches (:se ignorecase) or limit how far a search will go (:se nowrapscan). ":se all" displays all options available.
ZZ Writes file out and exits.
:q! Exits without saving.
:w [name] Write file to a different name as the file stands now and don't exit. name is optional.
[CTRL]-G On the bottom of the screen, displays the current file name, what line the cursor is on, if you have modified the file since it was last saved, and other information.
[n]yy "Yanks" n entire lines starting with the line the cursor is on and places them in a copy buffer. If the number of lines is omitted, only the current line is copied.
y[n]G Yanks the range of lines from the cursor to line n If n is omitted, the range is from the cursor to the end of the file.
[n]p Puts previously yanked lines into new lines below the cursor. Uppercase P inserts the lines above the cursor. Either command can be repeated as needed. When a count is specified, each line in the copy buffer is pasted n times before moving to the next line. Repeated p or P commands paste the entire copy buffer as copied, which may provide a more logical result.
For Yank, Put and Delete operations involving more than
five lines, a confirmation message is displayed by some
vi editors.


VI command reference

All of the commands shown are issued in Command Mode. While in Insert Mode, all characters typed except [ESC] become part of the file.

[ESC] exits Insert mode and goes to Command mode. Also aborts incomplete commands.
i Enters Insert mode. subsequent text is added in front of the cursor. Use [ESC] to get back to Command mode.
a Enters Insert mode and adds new text on right of cursor.
A Enters Insert mode and adds new text to end of line.
o Inserts a blank line below cursor and goes into Insert mode.
O Same as o, but opens line above cursor.
d[SPACE] Deletes one character.
dw Deletes up to next word.
de Deletes up to end of current word.
d0 Deletes from cursor to start of line.
dd Deletes entire line.
dnG Deletes a range of lines. d1G deletes from the current line to the first line of the file. dG deletes from the current line to the end of the file. If the cursor is on line 3, d6G deletes lines 3 through 6.
D Deletes from cursor to end of current line.
x Also deletes one character.
u Undoes last operation (insert, delete, substitute, etc.) Additional consecutive u's either undoes the undo or undoes previous operations (action depends on the version of vi used).
[LEFTARROW] or h Back up one space.
[DOWNARROW] or j Move down one line.
[UPARROW] or k Move up one line.
[RIGHTARROW] or l Move to the right.
[n] All movement and delete keys can be preceded by a number to repeat the operation, ie, 12j moves 12 lines down.
[n]G Moves to line n. If the number is omitted, move to last line.
/text Looks for next occurrence of text. Omitting text searches for previous string.
:%s/find/change/[g] Replace find with change in next occurrence. Adding 'g' to end of command changes all occurrences.
:se [no]modecommand Control things like case sensitivity in searches (:se ignorecase) or limit how far a search will go (:se nowrapscan). ":se all" displays all options available.
ZZ Writes file out and exits.
:q! Exits without saving.
:w name Write file to a different name as the file stands now and don't exit. name is optional.
[CTRL]-G On the bottom of the screen, displays the current file name, what line the cursor is on, if you have modified the file since it was last saved, and other information.
[n]yy "Yanks" n entire lines starting with the line the cursor is on and places them in a copy buffer. If the number of lines is omitted, only the current line is copied.
y[n]G Yanks the range of lines from the cursor to line n If n is omitted, the range is from the cursor to the end of the file.
[n]p Puts previously yanked lines into new lines below the cursor. Uppercase P inserts the lines above the cursor. Either command can be repeated as needed. When a count is specified, each line in the copy buffer is pasted n times before moving to the next line. Repeated p or P commands paste the entire copy buffer as copied, which may provide a more logical result.
For Yank, Put and Delete operations involving more than five lines, a confirmation message is displayed by some vi editors.


[Copyright 1984,2000,2001,2002,2016 Frank Durda IV, All Rights Reserved.
Mirroring of any material on this site in any form is expressly prohibited.
The official web site for this material is:  http://nemesis.lonestar.org
Contact this address for use clearances: clearance at nemesis.lonestar.org
Comments and queries to this address: web_reference at nemesis.lonestar.org]

Visit the nemesis.lonestar.org home page and index

Valid HTML 4.01!