Vim Commands

Essential Vim editor commands and keyboard shortcuts.

Vim Commands

Essential Vim editor commands and keyboard shortcuts

Modes

i

Enter insert mode (before cursor)

i
a

Enter insert mode (after cursor)

a
I

Insert at beginning of line

I
A

Insert at end of line

A
o

Open new line below

o
O

Open new line above

O
Esc

Exit insert mode to normal mode

Esc
v

Enter visual mode (character)

v
V

Enter visual mode (line)

V
Ctrl+v

Enter visual block mode

Ctrl+v

Navigation

h, j, k, l

Move left, down, up, right

k (move up)
w

Move to start of next word

w
b

Move to start of previous word

b
e

Move to end of word

e
0

Move to start of line

0
$

Move to end of line

$
gg

Go to first line

gg
G

Go to last line

G
:<number>

Go to line number

:42
Ctrl+u

Scroll up half page

Ctrl+u
Ctrl+d

Scroll down half page

Ctrl+d

Editing

x

Delete character under cursor

x
dd

Delete current line

dd
dw

Delete word

dw
d$

Delete to end of line

d$
yy

Yank (copy) current line

yy
yw

Yank word

yw
p

Paste after cursor

p
P

Paste before cursor

P
u

Undo

u
Ctrl+r

Redo

Ctrl+r
r

Replace single character

ra (replace with a)
cw

Change word

cw
cc

Change entire line

cc

Search & Replace

/pattern

Search forward

/function
?pattern

Search backward

?class
n

Next search result

n
N

Previous search result

N
:%s/old/new/g

Replace all in file

:%s/foo/bar/g
:s/old/new/g

Replace all in line

:s/foo/bar/g
:%s/old/new/gc

Replace with confirmation

:%s/foo/bar/gc

File Operations

:w

Save file

:w
:w filename

Save as filename

:w newfile.txt
:q

Quit

:q
:q!

Quit without saving

:q!
:wq

Save and quit

:wq
:x

Save and quit (shorter)

:x
:e filename

Open file

:e config.js
:bn

Next buffer

:bn
:bp

Previous buffer

:bp

Advanced

.

Repeat last command

.
>

Indent line

>>
<

Unindent line

<<
=

Auto-indent

==
J

Join line with next

J
~

Toggle case

~
*

Search word under cursor

*
Ctrl+n

Auto-complete (insert mode)

Ctrl+n