Show Menu
Cheatography

Vim Cheat sheet Keyboard Shortcuts (DRAFT) by

Vim Cheat sheet with commands and shortcuts

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

File Commands

:e filename
open a file in vim
:E
open a file explorer window
:wq
save changes in the current file and quit
:w filename
save changes in the current file or in the new file if filename was provided
:saveas filename
save changes in the new file
:q
quit Vim
:q!
quit Vim without saving changes

Navigation

h
move left
j
move down
k
move up
l
move right
w
move to the start of the next word
gg
go to the start of a file
G
go to the end of a file
50G
jump to the line 50
:50
jump to the line 50

Edit mode

i
enter insert mode at cursor
I
enter insert mode at the start of the line
a
enter append mode after cursor
A
enter append mode at the end of the line

Deleting Text

x
delete character
dd
delete line
D
delete to end of line
daw
delete a word (regar­dless of cursor position within that word)
das
delete entire sentence (ending with a . / ? / !)
dap
delete entire paragraph
dat
delete a tag (while cursor position is on that tag)
da}
or
di}
delete section between curly braces (while cursor position is within them)

Undo & Redo

u
undo
CTRL+r
redo

Copying and Pasting

yy
yank/copy line
yaw
yank/copy a word
p
paste after cursor
P
paste before cursor
 

Find & Replace

/
start pattern serach
n
repeat search in the same direction
N
repeat search in the opposite direction
f<C­HAR­ACT­ER>
find character forward
F<C­HAR­ACT­ER>
find character backward
:s/foo­/bar/g
replace all 'foo' with 'bar' in the current line
:%s/fo­o/bar/g
replace all 'foo' with 'bar' in the whole document
:retab
replace tab with spaces

Macros

qa
start recording a macro in the
a
registry
q
stop recording a macro
@a
replay a macro stored in
a
registry
:reg a
look at the contents of a registry
0
as a first step of the macro to start on the beginning of the line
j
used at the end of macro to move the cursor to the next line, so that it would be easy to repeat a macro
:20,100 normal @a
apply a macro from an
a
registry for the lines in range 20 - 100

Windows and Files

:split
or
:sp
split the window horizo­ntally
:vsplit
or
:vs
split the window vertically
CTRL + w
navigate between split windows (can be followed with a motion key)
:bn
go to the next file
:bp
go to the previous file
:bd
close the current file

Text alignment

:center
center text (can be selected in visual mode) to the width of 80
:left
left align
:left 5
left align text with 5 spaces indent­ation
:right
right align text to the width 80

Visual mode

v
start visual mode
V
start linewise visual mode
CTRL + v
start visual block mode (column edit)
gv
reselect the same bit of text
V
, select,
J
start linewise visual mode, select few lines and join them into a single line with
J
~
switch case
c
change text
d
delete text
y
yank
r
replace text
x
delete
I
insert
A
append
J
join
U
make uppercase
u
make lowercase
>
shift right
<
shift left