VIcmds.com

Please consider helping us maintain this site by making a donation:

Donate

A Reference for the VI Editor

Visit our new Blog!
Click here for Tips and Tricks!
Follow us on Twitter!

Master VI Cheat Sheet

Cursor
hmove left
lmove right
jmove down
kmove up
w, W/b, Bmove forward/backward by word
emove to end of word
Emove to end of word (includes punctuation)
), (beginning of next, previous sentence
}, {beginning of next, previous paragraph
]], [[beginning of next, previous section (normally defined by an opening '{')
Scrolling
[CTRL-F], [CTRL-B]Scroll forward, backward one screen
[CTRL-D], [CTRL-U]Scroll down, up one-half screen
[CTRL-E], [CTRL-Y]Scroll down, up one line
z [RETURN]Scroll so that line with cursor is at top of screen
z .Scroll so that line with cursor is at middle of screen
z -Scroll so that line with cursor is at bottom of screen
[CTRL-L]Redraw screen (without scrolling)
Line number
[CTRL-G]Display current line number
nGMove to line number n
GMove to last line in file
:nMove to line n
Insert
i, aInsert text before, after cursor
I, AInsert text before beginning, after end of line
o, OOpen new line for text below, above cursor
Delete/Move
xDelete character under cursor
XDelete character before cursor
dwDelete word
ddDelete current line
dmotionDelete text between cursor and the target of motion
DDelete to the end of line
p, PPut deleted text after, before cursor
"npPut text from delete buffer number n after cursor (for last nine deletions)
Exit commands
ZZWrite (save) the file if modified, and quit file
:xWrite (save) the file if modified, and quit file
:wqWrite (save) the file unconditionally, and quit the file
:wWrite (save) the file
:w!Write (save) the file, overriding protection
:30, 60w newfileWrite from line 30 through line 60 to newfile
:30, 60w>>fileWrite from line 30 through line 60 and append to file
:w %.newWrite current buffer named file as file.new
:qQuit file
:q!Quit file, overriding protection
QQuit vi and invoke ex
:e file2Edit file2 without leaving vi
:r newfileRead contents of newfile into current file
:nEdit next file
:e!Return to version of current file at time of last write (save)
:e #Edit alternate file
:viInvoke vi from ex
:Invoke one ex command from vi editor
%Current filename (substitutes into ex command line)
#Alternate filename (substitutes into ex command line)
^]Look up the location of the identifier under the cursor in the tags file and move to that location. If tag stacking is enabled, the current location is automatically pushed onto the tag stack.
^TReturn to the previous location in the tag stack, i.e. pop off one element
Lines
[RETURN]First non-blank character of next line
0, $First, last position of current line
^First non-blank character of current line
+, -First non-blank character of next, previous line
n|Column n of current line
HTop line of screen
MMiddle line of screen
LLast line of screen
nHn (number) of lines after top line
nLn (number) of lines before last line
Searches
/patternSearch forward for pattern
?patternSearch backward for pattern
n, NRepeat last search in same, opposite direction
/, ?Repeat previous search forward, backward
fxSearch forward for character x in current line
FxSearch backward for character x in current line
txSearch forward to character before x in current line
TxSearch backward to character after x in current line
;Repeat previous current-line search
,Repeat previous current-line search in opposite direction
:1,$s/x/y/gGlobally replace x with y
Marking position
mxMark current position as x
`xMove cursor to mark x
``Return to previous mark or context
'xMove to beginning of line containing mark x
''Return to beginning of line containing previous mark
Change
rReplace character
cwChange word
ccChange current line
cmotionChange text between the cursor and the target of motion
CChange to end of line
RType over (overwrite) characters
sSubstitute: delete character and insert new text
SSubstitute: delete current line and insert new text
Yank (copy)
ywYank (copy) word
yyYank current line
"ayyYank current line into named buffer a (a-z). Uppercase names append text.
ymotionYank text between the cursor and the target of motion
p, PPut yanked text after, before cursor
"aPPut text from buffer a before cursor (a-z)
ex edit commands
:dDelete lines
:mMove lines
:co or :tCopy lines
:.,$dDelete from current line to end of file
:30, 60m0Move lines 30 through 60 to top of file
:.,/pattern/co$Copy from current line through line containing pattern to end of file
Other commands
.Repeat last edit command
u, UUndo last edit; restore current line
JJoin two lines