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 ZZi / a / o / I / A / OEnter 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 :wCursor Movement
h / j / k / lMove one character left / down / up / right. (Arrow keys work too.)
5j — move 5 lines downw / b / e / W / B / EMove by word (PUNCT and BLANKS separated); W/B/E on whitespace-separated words.
wdw ; 3W to third whitespace-word forward0 / $ / ^Hard start of line / end of line / first non-blank.
0 to start ; $ to end ; ^ to first non-blankgg / G / :NFirst line / last line / jump to line N. Move with percentages: 50%.
gg=G format the entire file (with =)H / M / L / Ctrl-d / Ctrl-uTop / 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 forwardf<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 commaInsert Mode
Ctrl-h / Ctrl-w / Ctrl-uBackspace / 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 10Edit Operators
d / x / X / cDelete / 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 liney / yy / YYank (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 cursorp / P / gp / gPPaste 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 endu / Ctrl-r / UUndo / 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 linesr / R / J / gqReplace 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 paragraphIndent
>> / << / = / :set autoindentIndent / 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 / NSearch 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/gSubstitute — 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 linesBuffers, Tabs, Windows
:e file / :b<N> / :bn :bp :lsOpen 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/lSplit 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 / :tabcloseUse tabs when you want one-buffer-per-task screens.
:tabnew README.md gt gT :tabclose :tabonlyView & Setting
:set nu / :set relativenumberToggle line numbers; `relativenumber` shows distance from cursor (great with motions).
:set relativenumber && 5j will count in your head:set syntax on / :set filetype=tsEnable syntax highlighting / force a file type for an extensionless file.
:set ft=markdown ; :set bg=dark for dark mode:set paste / :set wrap / :set hlsearchPaste toggles: paste avoids auto-indent on insert. hlsearch persists matches.
:noh clear highlight now
:set paste then i<Ctrl-r>+ in some terminalsVisual & Block Mode
v / V / Ctrl-vVisual / 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 / :regUse 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 rowsExternal
:!cmd / :r !cmdRun a shell command from inside Vim; :r !cmd inserts its output.
:r !date ; :!%:clean :r ...:r file / :source file.vimRead 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+):terminalOpen 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 liveCheatsheet version 1.0.0
Covers Vim 9 / Neovim 0.9+