All cheatsheets

Vim Cheat Sheet

Quick reference for Vim / Neovim: modes, cursor motion, editing, search & replace, multi-file navigation, registers / macros and visual-block edits — with short examples for the most common moves.

37 commands

Modes & Saving

:w / :q / :wq / :q!

Save, quit, save-and-quit, force-quit without saving.

:w file (save as); :w! (force); :x (save & quit if modified); :qa! force-quit all; :wqa

:w | :q or ZZ
i / a / o / I / A / O

Enter Insert mode: i before / a after cursor; o / O open line below / above; I/A at line end.

i edit here => o new line + insert => I line-beginning => A line-end
<Esc> / Ctrl-[

Return to Normal mode (also use Ctrl-c / Ctrl-[). A blink cancel-pending operators.

i Hello<Esc> ; then :w

Cursor Movement

h / j / k / l

Move one character left / down / up / right. (Arrow keys work too.)

5j — move 5 lines down
w / b / e / W / B / E

Move by word (PUNCT and BLANKS separated); W/B/E on whitespace-separated words.

wdw ; 3W to third whitespace-word forward
0 / $ / ^

Hard start of line / end of line / first non-blank.

0 to start ; $ to end ; ^ to first non-blank
gg / G / :N

First line / last line / jump to line N. Move with percentages: 50%.

gg=G format the entire file (with =)
H / M / L / Ctrl-d / Ctrl-u

Top / middle / bottom of screen (H/M/L); half-page down (Ctrl-d) / up (Ctrl-u).

Ctrl-d and Ctrl-u to scan; 10Ctrl-f full page forward
{ / } / ( / )

Jump by paragraph (curly braces) or sentence (parens, ASCII text).

5{ ; 2} to jump two paragraphs forward
f<char> / F<char> / t / T ; ; / ,

Find / reverse-find the next char on the line (f/F); repeat with ; / ,. t/T stop before.

f, brings the cursor to the next comma ; df, deletes through next comma

Insert Mode

Ctrl-h / Ctrl-w / Ctrl-u

Backspace / delete word / delete line while typing — make coding-vim feel ergonomic.

i hello world<Ctrl-w> leaves 'hello '
Ctrl-o <cmd> / Ctrl-r <reg>

Run a single normal-mode command (Ctrl-o); paste register into insert (Ctrl-r).

Ctrl-r = expr to evaluate an expression on the fly

Ctrl-r " the unnamed register ; Ctrl-r 0 from the yank register ; Ctrl-r =5+5 to insert 10

Edit Operators

d / x / X / c

Delete / delete char under / before / change (delete + enter insert). Combine with motion: dw/xp/c$.

dd delete line; cc change line; D delete to EOL; C change to EOL

dw | dw$ | dw | 3dd | C reformat current line
y / yy / Y

Yank (copy). yy / Y yank current line; y$ / yW etc. take a motion.

y2w yy p gp — yank 2 words, line, paste, paste below without moving cursor
p / P / gp / gP

Paste after (p) / before (P) the cursor. gp/gP leave the cursor at the end of pasted text.

p below current ; P above ; gp after, cursor at end
u / Ctrl-r / U

Undo / redo (Ctrl-r). U restores the line to original (deprecated in favor of repeatable counts).

u u u ; Ctrl-r Ctrl-r ; 5u to undo last 5 changes
. / @: / q:

Repeat the last edit (.) — extremely powerful. @: repeats a recent macro; q: opens the command history.

i Monday<Esc> ; then . . . . across several lines
r / R / J / gq

Replace single char (r<char>) / enter Replace mode (R) / join lines (J, gJ without space) / format (gq{motion}).

raZ to change one char ; J to join ; gqap format the current paragraph

Indent

>> / << / = / :set autoindent

Indent / dedent / auto-indent (=). Combines with motion: =G to the end; `gg=G` format whole file.

5>> indent 5 lines ; =ap auto-indent paragraph ; gg=G format buffer (whole file)

Search & Replace

/pat / ?pat / n / N

Search forward (/) / backward (?); n / N repeat in the same / opposite direction.

/\<word\> word boundary; \v very-magic regex; \c ignore case; \C case-sensitive

/TODO\c ; n next ; N previous ; * / # to search the word under cursor
* / # / g* / g#

Search for the word under cursor: * forward (# backward). g* includes adjacent boundary.

Hover on foo then * — jumps to next foo, n continues
:%s/pat/rep/g / :5,12s/foo/bar/g

Substitute — global, with optional ranges, flags and confirm per match.

%s / g global; /c confirm; /i ignore case; /I case; /e no error; /n count

:%s/\bfoo\b/bar/gc — replace whole word "foo" with "bar", confirm each
:g/pat/d / :v/pat/m$

Operate on matches: :g/pat/d delete lines matching; :v/pat/m$ move non-matching to end.

:v/^#\|^$/d delete all comment-blank only lines

Buffers, Tabs, Windows

:e file / :b<N> / :bn :bp :ls

Open another file (:e), list (`:ls`), go to a buffer by id (`:b 3`), next/prev (`:bn`/`bp`).

:e . file explorer; :bd delete current buffer; :bn! force; hidden

:e src/index.ts :ls :b 3 :bp :bn
:sp :vs / Ctrl-w j/k/h/l

Split horizontally/vertically; Ctrl-w + motion to move between windows.

:vs src/index.ts | Ctrl-w l | Ctrl-w j — work in adjacent panes
:tabnew / gt / gT / :tabclose

Use tabs when you want one-buffer-per-task screens.

:tabnew README.md gt gT :tabclose :tabonly

View & Setting

:set nu / :set relativenumber

Toggle line numbers; `relativenumber` shows distance from cursor (great with motions).

:set relativenumber && 5j will count in your head
:set syntax on / :set filetype=ts

Enable syntax highlighting / force a file type for an extensionless file.

:set ft=markdown ; :set bg=dark for dark mode
:set paste / :set wrap / :set hlsearch

Paste toggles: paste avoids auto-indent on insert. hlsearch persists matches.

:noh clear highlight now

:set paste then i<Ctrl-r>+ in some terminals

Visual & Block Mode

v / V / Ctrl-v

Visual / line-visual / block-visual — block lets you edit columns of text.

v -> o toggle endpoints of selection in visual mode

Ctrl-v 5j I // Esc — prepend // to 6 lines (classic comment-uncomment)
gv / o (in visual)

Re-select the previous visual area; `o` toggles the active end of the selection.

Make a block selection, change something, run the same edit again with .

Registers & Macros

"ayy / "ap / :reg

Use a named register a to yank, then paste from a. :reg lists all registers.

"0 last yank; "_ black hole; "+ system clipboard (if +clipboard)

"ayy "ap ; :reg to list named, 0, +, *
q<reg> ... q / @<reg> / @@

Record a macro into register <reg>, replay with @<reg>; @@ repeats the last macro.

qa I" <Esc> $ " <Esc> q 5j @a — quote cells across rows

External

:!cmd / :r !cmd

Run a shell command from inside Vim; :r !cmd inserts its output.

:r !date ; :!%:clean :r ...
:r file / :source file.vim

Read contents of file at cursor; :source runs a Vim script (.vimrc, plugin file).

:r ~/.vimrc to paste whole config; :runtime! syntax/foo.vim
:help <topic>

Vim's offline help is excellent. `Ctrl-]` jumps to the tag under cursor.

:help gq :help motion.txt :help :terminal — open terminal-in-vim (8.0+)
:terminal

Open an embedded terminal (Vim 8+ / Neovim).

:vert terminal splits vertically; :term bash; Ctrl-w N : leave terminal mode

:vert term bash :resize 15 && run tests live

Cheatsheet version 1.0.0

Covers Vim 9 / Neovim 0.9+