Unix Manuals

vi reference

Text Link Ads

This reference guide to the vi editor presents the majority of vi commands and keys. We hope you find it useful. We also recommend two good books on vi, (one a tutorial, and one a reference guide).

NOTICE - New forum for all UNIX learners, users and programmers - click here

Cursor control and position

h Left
Text Link Ads


j Down
k Up
l (or spacebar) Right
w Forward one word
b Back one word
e End of word
( Beginning of current sentence
) Beginning of next sentence
{ Beginning of current paragraph
} Beginning of next paragraph
[[ Beginning of current section
]] Beginning of next section A Append to end of current line
0 Start of current line i Insert before cursor
$ End of current line I Insert at beginning of line
^ First non-white character of current line o Open line above cursor
+ or RETURN First character of next line O Open line below cursor
- First character of previous line ESC End of insert mode
n | character n of current line Ctrl-I Insert a tab
H Top line of current screen Ctrl-T Move to next tab position
M Middle line of current screen Backspace Move back one character
L Last line of current screen Ctrl-U Delete current line
nH n lines after top line of current screen Ctrl-V Quote next character
nL n lines before last line of current screen Ctrl-W Move back one word
Ctrl-F Forward one screen cw Change word
Ctrl-B Back one screen cc Change line
Ctrl-D Down half a screen C Change from current position to end of line
Ctrl-U Up half a screen dd Delete current line
Ctrl-E Display another line at bottom of screen ndd Delete n lines
Ctrl-Y Display another line at top of screen D Delete remainer of line
z RETURN Redraw screen with cursor at top dw Delete word
z . Redraw screen with cursor in middle d} Delete rest of paragraph
z - Redraw screen with cursor at bottom d^ Delete back to start of line
Ctrl-L Redraw screen without re-positioning c/pat Delete up to first occurance of pattern
Ctrl-R Redraw screen without re-positioning dn Delete up to next occurance of pattern
/text Search for text (forwards) dfa Delete up to and including a on current line
/ Repeat forward search dta Delete up to, but not including, a on current line
?text Search for text (backwards) dL Delete up to last line on screen
? Repeat previous search backwards dG Delete to end of file
n Repeat previous search J Join two lines
N Repeat previous search, but it opposite direction p Insert buffer after cursor
/text/+n Go to line n after text P Insert buffer before cursor
?text?-n Go to line n before text rx Replace character with x
% Find match of current parenthesis, brace, or bracket. Rtext Replace text beginning at cursor
Ctrl-G Display line number of cursor s Substitute character
nG Move cursor to line number n ns Substitute n characters
:n Move cursor to line number n S Substitute entire line
G Move to last line in file u Undo last change
    U Restore current line
Text Link Ads
x Delete current cursor position
X Delete back one character
nX Delete previous n characters
. Repeat last change
~ Reverse case
y Copy current line to new buffer
yy Copy current line
"xyy Copy current line into buffer x
"Xd Delete and append into buffer x
"xp Put contents of buffer x
y]] Copy up to next section heading
ye Copy to end of word

File Handling

:w Write file

:w! Write file (ignoring warnings)
:w! file Overwrite file (ignoring warnings)
:wq Write file and quit
:q Quit
:q! Quit (even if changes not saved)
:w file Write file as file, leaving original untouched
ZZ Quit, only writing file if changed
:x Quit, only writing file if changed
:n1,n2w file Write lines n1 to n2 to file
:n1,n2w >> file Append lines n1 to n2 to file
:e file2 Edit file2 (current file becomes alternate file)
:e! Reload file from disk (revert to previous saved version)
:e# Edit alternate file
% Display current filename
# Display alternate filename
:n Edit next file
:n! Edit next file (ignoring warnings)
:n files Specify new list of files
:r file Insert file after cursor
:r !command Run command, and insert output after current line

We hope you find this reference useful, and that you'll bookmark it and come back to it whenever you need to. However, if you want a vi reference actually on your desk, then our friends over at www.geekcheat.com produce a vi reference mug, mousemat and even a T-shirt (printed upside-down, so the wearer can read it). It's well worth a look...

This web site is provided entirely free of charge. However, if you would like to make a donation, which will encourage the development of new material, we would very much appreciate it - please click on the button below - thank you!


© Copyright 2000-2001, Tom Reader, All Rights Reserved.
UNIX is a registered trademark of The Open Group in the US and other countries.
For more information on the use of the UNIX trademark, click here.
The contents of this site are not connected with or endorsed by The Open Group in any way.