Vim Commands

Essential Vim editor commands and keyboard shortcuts.

Modes

i

Enter insert mode (before cursor)

a

Enter insert mode (after cursor)

I

Insert at beginning of line

A

Insert at end of line

o

Open new line below

O

Open new line above

Esc

Exit insert mode to normal mode

v

Enter visual mode (character)

V

Enter visual mode (line)

Ctrl+v

Enter visual block mode

Navigation

h, j, k, l

Move left, down, up, right

w

Move to start of next word

b

Move to start of previous word

e

Move to end of word

0

Move to start of line

$

Move to end of line

gg

Go to first line

G

Go to last line

:<number>

Go to line number

Ctrl+u

Scroll up half page

Ctrl+d

Scroll down half page

Editing

x

Delete character under cursor

dd

Delete current line

dw

Delete word

d$

Delete to end of line

yy

Yank (copy) current line

yw

Yank word

p

Paste after cursor

P

Paste before cursor

u

Undo

Ctrl+r

Redo

r

Replace single character

cw

Change word

cc

Change entire line

Search & Replace

/pattern

Search forward

?pattern

Search backward

n

Next search result

N

Previous search result

:%s/old/new/g

Replace all in file

:s/old/new/g

Replace all in line

:%s/old/new/gc

Replace with confirmation

File Operations

:w

Save file

:w filename

Save as filename

:q

Quit

:q!

Quit without saving

:wq

Save and quit

:x

Save and quit (shorter)

:e filename

Open file

:bn

Next buffer

:bp

Previous buffer

Advanced

.

Repeat last command

>

Indent line

<

Unindent line

=

Auto-indent

J

Join line with next

~

Toggle case

*

Search word under cursor

Ctrl+n

Auto-complete (insert mode)