Show Menu
Cheatography

Vim Cheat Sheet (DRAFT) by

Vim cheat sheet made from Vimtutor

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Motions

h
move cursor left
j
move cursor down
k
move cursor up
l
move cursor right
w
move to the start of the next word
3w
move forward 3 words (not counting the word under the cursor) and place cursor at the start of that word
e
(a) if cursor at end of current word, then move to the end of the next word
(b) otherwise, move to the end of the current word
3e
move forward 3 words (not counting the word under the cursor) and place cursor at the start of that word
0
move to the start of the line
$
move to the end of the line
G
move cursor to the last line of the document
5G
move cursor to the 5th line of the document
gg
move cursor to the first line of the document
%
find next item (, [, or { in this line after or under the cursor and jump to matching item ), ], or }. Type % again to jump back to the matching item (, [, or {.
<C-o>
go to older cursor position in jump list (note that a "­jum­p" is a command that normally moves the cursor several lines away, e.g., gg)
<C-­i>
go to newer cursor position in jump list (note that a "­jum­p" is a command that normally moves the cursor several lines away, e.g., gg)

Insert Mode

i
insert text before the cursor
a
insert text after the cursor
A
insert text after the end of the line
o
open a line below the cursor and start Insert mode
O
open a line above the cursor and start Insert mode
<Esc>
exit insert mode

Open, Save, & Exit

:q!
exits the editor, discarding any changes you have made
:wq
save file and exit
:w file
writes the current Vim file to disk named file
:r file
insert the contents of the file below cursor line
:r !cmd
insert output of external command cmd below cursor line

Cut/Copy & Past

x
delete (cut) character under cursor (does the same as dl, and acts the same as <De­l> key)
X
delete (cut) character before cursor (acts the same as <Bk­sp> key)
dw
delete (cut) from the cursor postion to the start of the next word (excluding its first character)
3wd
delete (cut) the characters of the word from the cursor postion to the start of the 3rd word foreward (not counting the word under the cursor and excluding the first character of kth word)
de
(a) if cursor at end of current word, then delete (cut) from the cursor position to the end of the next word (including the last charac­ter).
(b) Otherwise, delete (cut) from the cursor postion to the end of the word (including the last charac­ter).
d$
delete (cut) from cursor to the end of the line (including the last character)
dd
delete (cut) whole line
3dd
delete (cut) 3 lines (on and below cursor)
y
yanks (copies) text (p puts (pastes) it)
p
put previously deleted text after the cursor. If a line was deleted it will go on the line below the cursor.

Editing Text

rx
replace the character at the cursor with x
R
enters Replace mode until <Es­c> is pressed. Replace mode is like Insert mode, but every typed character deletes an existing character
cw
deletes until the start of the next word (excluding its first character) and switches to Insert mode
ce
(a) if cursor at end of current word, then delete until the end of the next word (including its last character) and switches to Insert mode.
(b) otherwise, delete until the end of a word (including its last character) and switches to Insert mode.
c$
deletes to the end of the line and switches to Insert mode
u
undo the last command
U
undo all changes on a line
<C-p>
undo the undo (redo)

Search & Replace

/pattern
searches forward for the pattern in the document
?pattern
searchs backward for pattern in document
n
repeat search in same direction
N
repeat search in opposite direction
:s/old/new
substitute 'new' for the first 'old' in the current line
:s/old­/new/g
substitute 'new' for 'old' (all occurr­ences) in the current line
:#,#s/old/new/g
substitute 'new' for 'old' in the range of line numbers of #,#
:%s/ol­d/new/g
substitute 'new' for 'old' in the entire document
:%s/ol­d/n­ew/gc
substitute 'new' for 'old' in the entire document, with a prompt whether to substiute or not
 

Visual Mode

v
Start visual mode. Use the normal movement keys and commands to select text for highli­ghting.
v motion
:w file
writes the Visually selected text (via motion) to file
<Es­c>
exit visual mode

Miscel­laneous

<C-­g>
show your location in the file and the file status
:!cmd
allows you to execute any external shell command cmd (e.g., :!ls -al)
:h
open help window (<C­-w> to jump from one window to another, and :q <CR> to close help window)
:h cmd
open help for command cmd
:e <C-­d>
Vim will show list of all commands that start with "­e"
:e <C-d)><Tab>
Vim will complete the name that starts with "­e"

Optional Settings

:set xxx
sets the option xxx
:set ic
ignore upper/­lower case when searching
:set is
show partial matches for a search phrase
:set hls
highlight all matching phrases
prepend "­­no­" to argument option to switch option off