Vim Cheat Sheet
Movement Commands
0 move to beginning of line where cursor is
present
w move to start of next word
b move to beginning of current word
4j/4k move four up or four down (or any selected
number)
Insert / Append Commands
i insert before cursor
a insert after cursor
A insert at end of line
o open a newline, below cursor
ctrl-n insert next keyword
ctrl-p insert next/previous keyword
Delete Commands
x delete character
d$ delete from cursor to end of line
dd delete whole line
ce delete from cursor to end of word and
enter Insert mode
c$ delete from cursor to end of line and
enter Insert mode
d5w delete five words (or any selected number)
Put Commands
p put text back after deletion or put line
below cursor (using register contents from
dd)
Paste Commands
set paste paste pre-formatted text into vim (disable
formatting)
set nopaste re-enable paste formatting
Undo / Redo Commands
u undo previous
U undo line
ctrl-r redo
Replace Commands
r replace (follow with char)
Status and File Position Commands
ctrl-g show location and file status
gg move to top of file
G move to bottom of file
66-G move to line 66
/string search for string (n for next, N for
previous, ctrl-o return to previous position)
% move from cursor highlighted (,),{,},[ or ]
to matching parenthesis or bracket
Substitution Commands
:s/old/new substitute old word with new. Use
:s/old/new/g for global substitution
(one line).
:#,#s/old/new/g substitute phrases between two line
#'s
:%s/old/new/g substitute all occurrences in the
file type
:%s/old/new/gc ask for confirmation each time add
'c'
Execute External Commands
:![command] execute any external command (for
example browse files
Save File Commands
SHIFT+zz saves file and exits (same as :wq)
:w FILENAME saves current as "FILENAME"
Visual Mode Commands
v enter Visual Mode
v+selection save selection with :w FILENAME
Hot tips
:w !sudo tee % save a file that needs root
permission (must have sudo
privileges)
:w !sudo tee > /dev/null % same as above but without
echo to stout