Cheatsheet: Vim

Last updated 2026-09-27

Modes

Enter insert mode before/after cursor

i / a

Insert at start/end of line

I / A

Open a new line below/above and enter insert mode

o / O

Return to normal mode

Esc

Visual mode: character-wise / line-wise / block-wise

v / V / Ctrl-v

Replace mode (typing overwrites existing characters)

R

Motions & Navigation

Left, down, up, right

h j k l

Word forward / word backward / end of word

w / b / e

Start / end of line

0 / $

First non-blank character of line

^

Go to line N (or last line with no count)

:N or NG

Top / middle / bottom of screen

H / M / L

Jump to matching bracket/paren

%

Search forward / backward, repeat, repeat reversed

/pattern, ?pattern, n, N

Find character forward/backward on the current line, till before it

f{char} / F{char} / t{char}

Editing

Delete character / delete line

x / dd

Yank (copy) line / paste after / paste before

yy / p / P

Change (delete + insert) to end of word

cw

Undo / redo

u / Ctrl-r

Repeat last change

.

Join current line with the next

J

Indent / unindent selected lines

>> / <<

Delete inner word / a parenthesized expression / inner quotes

diw / da( / ci"

Prefix any operator/motion with a count

3dd, 5j, 2yy

Search & Replace

Replace all occurrences on the current line

:s/old/new/g

Replace all occurrences in the whole file

:%s/old/new/g

Replace with confirmation for each match

:%s/old/new/gc

Case-insensitive replace

:%s/old/new/gi

Replace within a visual selection (auto-fills the range)

:'<,'>s/old/new/g

Match whole word only

:%s/\<foo\>/bar/g

Buffers, Windows & Tabs

List open buffers

:ls

Switch to buffer by number/name

:b {N or name}

Split window horizontally / vertically

:split / :vsplit

Move focus between windows

Ctrl-w then h/j/k/l

Open a new tab / go to next tab

:tabnew / gt

Save file / save and quit / quit discarding changes

:w / :wq / :q!

Save only if modified, then quit

:x

Common :set Options

Show line numbers

:set number

Highlight search matches

:set hlsearch

Case-insensitive search (unless a capital letter is typed)

:set ignorecase smartcase

Use spaces instead of tabs, with a given width

:set expandtab tabstop=4 shiftwidth=4

Persist a setting across sessions

add the line to ~/.vimrc

FAQ