Show Menu

VI Editor Cheat Sheet by ericg

VI Editor shortcuts and modes.


:xExit, saving changes
:qExit as long as there have been no changes
ZZExit and save changes if any have been made
:q!Exit and ignore any changes

Inserting Text

iInsert before cursor
IInsert before line
aAppend after cursor
AAppend after line
oOpen a new line after current line
OOpen a new line before current line
rReplace one character
RReplace many characters


hMove left
jMove down
kMove up
lMove right
wMove to next word
WMove to next blank delimited word
bMove to the beginning of the word
BMove to the beginning of blank delimted word
eMove to the end of the word
EMove to the end of Blank delimited word
(Move a sentence back
)Move a sentence forward
{Move a paragraph back
}Move a paragraph forward
0Move to the begining of the line
$Move to the end of the line
1GMove to the first line of the file
GMove to the last line of the file
nGMove to nth line of the file
:nMove to nth line of the file
fcMove forward to c
FcMove back to c
HMove to top of screen
MMove to middle of screen
LMove to botton of screen
%Move to associated ( ), { }, [ ]
:0Move to the beginning of the file
:$Move to the end of the file
[ctrl] + dgo down half a screen
[ctrl] + ugo up half a screen
[ctrl] + fgo forward a screen
[ctrl] + bgo back a screen


Vi has two modes insertion mode and command mode. The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode (where you can quit, for example by typing :q!). Most commands execute as soon as you type them except for "­col­on" commands which execute when you press the ruturn key.

Deleting Text

xDelete character to the right of cursor
XDelete character to the left of cursor
DDelete to the end of the line
ddDelete current line
:dDelete current line

Yanking Text

yyYank the current line
:yYank the current line

Changing text

CChange to the end of the line
ccChange the whole line
guulowercase line
gUUuppercase line
~Toggle upp and lower case

Putting text

pPut after the position or after the line
PPut before the poition or before the line


mcSet marker c on this line
`cGo to beginning of marker c line.
'cGo to first non-blank character of marker c line.

Search for strings

/stringSearch forward for string
?stringSearch back for string
nSearch for next instance of string
NSearch for previous instance of string


:s/pat­ter­n/s­tri­ng/­flagsReplace pattern with string according to flags.
gFlag - Replace all occurences of pattern
cFlag - Confirm replaces.
&Repeat last :s command


:n,mRange - Lines n-m
:.Range - Current line
:$Range - Last line
:'cRange - Marker c
:%Range - All lines in file
:g/pat­tern/Range - All lines that contain pattern


:w fileWrite to file
:r fileRead file in after line
:nGo to next file
:pGo to previous file
:e fileEdit file
!!pro­gramReplace line with output from program


JJoin lines
.Repeat last text-c­hanging command
uUndo last change
UUndo all changes to line

Share This Cheat Sheet!

Favourited by 30 Members:

Freaksed chrysa fkorling im_chc oronm Ammly leshkin internaciulo Theosis jeremic Veloz and 20 more ...


Linux Admin Linux Admin, 09:10 29 Feb 12

This is great, thank you to ericg for making this. A must have for vi noobs like myself.

ericg ericg, 09:49 2 Mar 12

You're welcome. Just add the :0 and :$

mishin mishin, 11:13 13 Jun 12

very good, thank you!

Alon Alon, 09:19 19 Jun 12

Please add Ctrl+r (Redo last change) to the Others block.

alexh alexh, 02:30 27 Jul 12

ahh.. thank you for compiling this. Very good!

James James, 12:51 22 Nov 12

Sorry, Ctl-R is Vim only, as is guu and gUU. To undo-redo in regular vim you do 'uu' which vim breaks with its multi-undo (but nvi doesn't with 'u.')

Remove the vim specific stuff, there is already a vim cheat sheet.

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.