EscLeave any mode and return to normal mode. The home base of vim.
Mnemonic: Escape = "get me out of here".
Esc
Ctrl+[ (same as Esc, doesn't need pinky)
Vim cheat sheet — 100+ commands covering modes, motions, edits, search, registers, splits, with mnemonics.
EscLeave any mode and return to normal mode. The home base of vim.
Mnemonic: Escape = "get me out of here".
Esc
Ctrl+[ (same as Esc, doesn't need pinky)
iEnter insert mode at the cursor — start typing text.
Mnemonic: i = insert (before cursor).
i
iHello World
aEnter insert mode after the cursor (append).
Mnemonic: a = append (after cursor).
a
a // comment
IInsert at the first non-blank character of the line.
Mnemonic: Capital I = Insert at line start.
I
I//
AAppend at the end of the line.
Mnemonic: Capital A = Append at end.
A
A;
oOpen a new line below and enter insert mode.
Mnemonic: o = open (line below).
o
ohello
OOpen a new line above and enter insert mode.
Mnemonic: Capital O = Open line above.
O
O# header
vEnter visual mode (character-wise) to select text.
Mnemonic: v = visual.
v
vw (select to next word)
vap (select around paragraph)
VEnter visual line mode — select whole lines.
Mnemonic: Capital V = Visual line (whole lines).
V
Vj (select 2 lines)
V}d (select to paragraph end and delete)
Ctrl+vVisual block mode — select a rectangular block. Lets you edit columns.
Mnemonic: Ctrl+v = vertical/block visual.
Ctrl+v
Ctrl+v 3j I// Esc (comment 3 lines with //)
REnter replace mode — typing overwrites existing characters.
Mnemonic: R = Replace continuously.
R
Rfoo (replace 3 chars with foo)
:Enter command mode — type Ex commands like :w, :q, :s.
Mnemonic: Colon = command line.
:w
:q
:wq
giRe-enter insert mode at the last place you left insert mode.
Mnemonic: g + i = "go back to where I was inserting".
gi
gvReselect the last visual selection (same range, same mode).
Mnemonic: g + v = "give me that visual selection back".
gv
gvd (reselect then delete)
o (in visual)In visual mode, jump the cursor to the other end of the selection so you can extend it from there.
Mnemonic: o = other end of the selection.
vjjo (then extend upward)
Ctrl+o (insert)From insert mode, run one normal-mode command then drop back into insert.
Mnemonic: Ctrl+o = "one normal command, then back".
Ctrl+o $ (jump to line end without leaving insert)
Ctrl+o dd
Ctrl+w (insert)Delete the word before the cursor while in insert mode.
Mnemonic: Ctrl+w = wipe a word (insert mode).
Ctrl+w
Ctrl+u (insert)Delete everything you typed on this line since entering insert mode (back to insert start).
Mnemonic: Ctrl+u = undo this line of typing (insert mode).
Ctrl+u
Ctrl+r (insert)Insert the contents of a register while in insert mode (Ctrl+r then the register letter).
Mnemonic: Ctrl+r in insert = read a register into the text.
Ctrl+r " (paste the unnamed register)
Ctrl+r 0 (paste last yank)
Ctrl+r + (paste system clipboard)
gJJoin the next line onto this one WITHOUT inserting a space (raw join).
Mnemonic: g + J = Join with no glue (no space).
gJ
3gJ
h / j / k / lMove left / down / up / right by one character. The classic vim arrow keys.
Mnemonic: h is leftmost on home row, l is rightmost. j hangs down like a hook, k kicks up.
h
5j (down 5 lines)
10l (right 10 chars)
wJump to the start of the next word (whitespace-separated tokens count).
Mnemonic: w = word (forward).
w
3w (forward 3 words)
WJump to next WORD — like w but only whitespace separates WORDs (foo.bar is one WORD).
Mnemonic: Capital W = bigger Word (skips punctuation).
W
dW (delete a WORD including dots)
bJump back to the start of the previous word.
Mnemonic: b = back (one word).
b
3b
eJump to the end of the current/next word.
Mnemonic: e = end of word.
e
de (delete to word end)
geJump backwards to the end of the previous word.
Mnemonic: g + e = "go end backwards".
ge
0Jump to the very first column of the line (column 0).
Mnemonic: Zero = column zero, the absolute start.
0
^Jump to the first non-blank character of the line.
Mnemonic: ^ points up to "the start of real content".
^
d^ (delete from cursor back to first non-blank)
$Jump to the end of the line.
Mnemonic: $ = end of line in regex too. Same idea.
$
d$ (delete to end of line, same as D)
ggJump to the first line of the file.
Mnemonic: gg = go to top.
gg
5gg (go to line 5)
GJump to the last line of the file (or to line N with NG).
Mnemonic: Capital G = Go to bottom.
G
120G (go to line 120)
:<N>Jump to line N (e.g. :42 jumps to line 42).
Mnemonic: Colon + number = "go to that line in the file".
:42
:1
{ / }Jump to previous / next blank-line-separated paragraph.
Mnemonic: Curly braces wrap a paragraph; the same key wraps your cursor to its boundary.
{}
d} (delete to end of paragraph)
( / )Jump to previous / next sentence (.!? boundary).
Mnemonic: Parens are sentence-shaped — small step.
(
)
Ctrl+uScroll up half a screen, cursor moves with it.
Mnemonic: u = up (half page).
Ctrl+u
Ctrl+dScroll down half a screen, cursor moves with it.
Mnemonic: d = down (half page).
Ctrl+d
Ctrl+fPage forward (down a full screen).
Mnemonic: f = forward a full page.
Ctrl+f
Ctrl+bPage backward (up a full screen).
Mnemonic: b = back a full page.
Ctrl+b
zz / zt / zbRecenter screen so cursor line is in the middle / top / bottom of the viewport.
Mnemonic: z = zoom/position, z+z centers (twins).
zz
zt
zb
H / M / LMove cursor to High (top) / Middle / Low (bottom) of the visible screen.
Mnemonic: H = High, M = Middle, L = Low — first letter of each position.
H
M
L
f<char> / F<char>Jump forward / backward to the next occurrence of <char> on this line.
Mnemonic: f = find (capital = backward).
f(
F"
df; (delete up to and including ;)
t<char> / T<char>Jump till just before / after <char> on this line (exclusive of the char).
Mnemonic: t = till (stop just before the target).
t)
dt; (delete up to but not including ;)
; / ,Repeat the last f/F/t/T motion forward / backward.
Mnemonic: ; goes again, , goes opposite (think comma = backward).
;
,
%Jump to the matching bracket — ( ), [ ], { }, even matching #if / #endif.
Mnemonic: % looks like two halves meeting — jump between matched pair.
%
d% (delete from cursor through matching bracket)
Ctrl+o / Ctrl+iJump back / forward through the jump list (like browser back/forward).
Mnemonic: o = older position, i = incoming (newer).
Ctrl+o
Ctrl+i
+ / -Move to the first non-blank character of the next / previous line.
Mnemonic: + goes down a line, - goes up — landing on real content.
+
-
3+ (down 3 lines to first non-blank)
|Jump to a specific column on the current line (N| goes to column N).
Mnemonic: The bar | is vertical — it picks a column.
1| (column 1)
40| (column 40)
g_Jump to the LAST non-blank character of the line (unlike $ which lands on the last char even if blank).
Mnemonic: g + _ = "go to last real character".
g_
dg_ (delete to last non-blank)
gj / gkMove down / up by a DISPLAY line (useful when a long line is wrapped onto several screen rows).
Mnemonic: g + j/k = move by visual rows, not logical lines.
gj
gk
nnoremap j gj (make j respect wrapping)
gd / gDJump to the local (gd) / global (gD) definition of the identifier under the cursor (keyword search, no index needed).
Mnemonic: g + d = go to definition (lowercase local, uppercase global).
gd
gD
]] / [[Jump to the next / previous section or top-level { in column 1 (forward / backward).
Mnemonic: Doubled brackets = jump between big code sections.
]]
[[
[{ / ]}Jump to the unmatched { before the cursor / } after the cursor — escape outward from inside a block.
Mnemonic: [{ goes to the opening brace that contains you, ]} to the closing one.
[{]}
[( / ])Jump to the unmatched ( before the cursor / ) after it — same idea as [{ ]} but for parentheses.
Mnemonic: Bracket + paren = jump to the enclosing parenthesis.
[(
])
Ctrl+e / Ctrl+yScroll the window down / up by one line WITHOUT moving the cursor (until it would leave the screen).
Mnemonic: Ctrl+e nudges the view down, Ctrl+y pulls it up.
Ctrl+e
Ctrl+y
3 Ctrl+e
g; / g,Jump to older / newer position in the change list (where you last edited).
Mnemonic: g; goes back through edits, g, goes forward.
g;
g,
`.Jump to the exact position of the last change in the file (the . mark).
Mnemonic: Backtick + . = "where did I just change something".
`.
'. (same but line-wise)
`^Jump to where the cursor was the last time insert mode was stopped.
Mnemonic: `^ = the insert-stopped mark.
`^
iw / awWord text objects: iw = inner word (no surrounding space), aw = a word (includes one adjacent space). Use after an operator.
Mnemonic: i = inner, a = around (a swallows a space too).
diw
daw
viw (select inner word)
ciw
ip / apParagraph text objects: ip = inner paragraph, ap = a paragraph (includes the trailing blank line).
Mnemonic: ip = inner paragraph, ap = around paragraph.
dap
vip
yap
it / atTag text objects (HTML/XML): it = inside the tag pair, at = the whole tag including <…> and </…>.
Mnemonic: it = inner tag, at = around tag.
dit
cit
dat
vat
xDelete the character under the cursor.
Mnemonic: x = X-out one char.
x
5x (delete 5 chars)
XDelete the character before the cursor (backspace in normal mode).
Mnemonic: Capital X = X-out backwards.
X
r<char>Replace the character under the cursor with <char>, no mode change.
Mnemonic: r = replace one (single shot).
ra
r) (turn a } into ))
sSubstitute character — delete the char under cursor and enter insert mode.
Mnemonic: s = substitute (delete + insert).
s
3sfoo (replace 3 chars with foo)
SSubstitute the whole line — delete it and enter insert mode at the indent level.
Mnemonic: Capital S = Substitute line (cc shortcut).
S
d<motion>Delete from cursor to wherever the motion goes (and yank into default register).
Mnemonic: d + motion = delete-that-motion.
dw (delete to next word)
d$ (delete to end of line)
d5j (delete current + 5 lines below)
ddDelete the whole current line.
Mnemonic: dd = double-d = delete line (motion is the line itself).
dd
3dd (delete 3 lines)
DDelete from cursor to end of line (same as d$).
Mnemonic: Capital D = "Delete the rest".
D
c<motion>Change — delete the motion range and enter insert mode in one step.
Mnemonic: c = change (delete + insert).
cw (change a word)
c$ (change to end of line, = C)
ci" (change inside quotes)
ccChange the whole line — delete it and enter insert mode at indent.
Mnemonic: cc = double-c = change line.
cc
CChange from cursor to end of line (same as c$).
Mnemonic: Capital C = "Change the rest".
C
y<motion>Yank (copy) the motion range into the default register.
Mnemonic: y = yank = pull text into register.
yw (yank a word)
y$ (yank to end of line)
yi( (yank inside parens)
yyYank the whole current line.
Mnemonic: yy = double-y = yank line.
yy
5yy (yank 5 lines)
pPaste after the cursor / below the current line if yanked content was line-wise.
Mnemonic: p = paste (after).
p
3p (paste 3 times)
PPaste before the cursor / above the current line.
Mnemonic: Capital P = Paste before.
P
uUndo the last change.
Mnemonic: u = undo.
u
5u (undo 5 changes)
Ctrl+rRedo — the inverse of u.
Mnemonic: Ctrl+r = redo (r = redo).
Ctrl+r
.Repeat the last change. The most underrated key in vim.
Mnemonic: Period = "do it again".
.
cw foo Esc j . (change next word to foo too)
>> / <<Indent / outdent current line by one shiftwidth.
Mnemonic: >> pushes right, << pushes left.
>>
3>> (indent 3 lines)
V}> (indent paragraph)
~Toggle case of the character under the cursor (advances cursor).
Mnemonic: Tilde looks wavy — wave between upper/lower.
~
5~ (toggle 5 chars)
guu / gUULowercase / uppercase the entire current line.
Mnemonic: g + u = go lowercase; g + U = go UPPERCASE.
guu
gUU
gUw (uppercase one word)
JJoin the next line onto the current one with a space in between.
Mnemonic: Capital J = Join (push lines together).
J
3J (join 3 lines)
di<obj> / da<obj>Delete inside / around a text object (word, quotes, parens, tag, etc.).
Mnemonic: i = inner, a = around (a = includes the delimiters).
diw (delete inside word)
di"
da(
dit (delete inside tag)
ci<obj> / ca<obj>Change inside / around a text object — like di/da but enters insert mode.
Mnemonic: c + text object = swap that thing.
ciw (change a word)
ci"
ci{ (change inside braces)xpSwap the current character with the next one (delete char, then paste it after).
Mnemonic: x deletes a char, p pastes it one spot later = swap.
xp (turn "teh" into "the" with cursor on e)
ddpSwap the current line with the one below it (delete line, paste below).
Mnemonic: dd cuts the line, p drops it back below = move line down.
ddp
ddkP (move line up)
Ctrl+a / Ctrl+xIncrement / decrement the number at or after the cursor on this line.
Mnemonic: Ctrl+a = add, Ctrl+x = subtract.
Ctrl+a
10 Ctrl+a (add 10)
Ctrl+x
g Ctrl+aIn a visual block of numbers, create an incrementing sequence (1, 2, 3 …) across the selected lines.
Mnemonic: g + Ctrl+a over a selection = staircase of increments.
Ctrl+v 4j g Ctrl+a (number 5 lines 1..5)
gp / gPPaste like p / P but leave the cursor just AFTER the pasted text (handy for chained pastes).
Mnemonic: g + p = paste and go past it.
gp
gP
]pPaste and re-indent the pasted lines to match the current line (great for moving code between indent levels).
Mnemonic: ]p = paste, adjusted to local indent.
]p
[p (paste above with indent fix)
o<Esc>Open a blank line below and immediately leave insert — a quick way to add an empty line.
Mnemonic: o opens a line, Esc bails out — leaves it empty.
o<Esc>
O<Esc> (blank line above)
cis / casChange inner / a sentence — swap out the sentence the cursor is in.
Mnemonic: c + i/a + s = change sentence.
cis
das (delete a sentence)
yi( / ya{Yank inside parentheses / around braces — copy the contents of a bracketed block.
Mnemonic: y + i/a + bracket = yank that bracketed thing.
yi(
ya{yi[ (yank inside square brackets)
g~<motion>Toggle case over a motion range (g~~ toggles the whole line).
Mnemonic: g + ~ = go toggle case over a range.
g~w (toggle a word)
g~~
g~$
=<motion>Auto-indent the motion range using the current indent rules (== for the current line).
Mnemonic: = means "make the indentation right".
==
=ap (reindent a paragraph)
gg=G (reindent whole file)
Ctrl+v $ ABlock-select to end of each line, then A appends the same text to every selected line at once.
Mnemonic: Block + $ + A = append to many line ends together.
Ctrl+v 3j $ A; Esc (add ; to 4 line ends)
/<pattern>Search forward for a regex pattern, hit Enter to jump to the first match.
Mnemonic: Slash = look ahead.
/foo
/^import.*react
/foo\c (case-insensitive for this search)
?<pattern>Search backward for a regex pattern.
Mnemonic: Question mark = "looking back to ask".
?TODO
?function
n / NJump to the next / previous search match (in original direction / opposite).
Mnemonic: n = next (same dir), N = opposite.
n
N
* / #Search for the word under cursor — forward (*) or backward (#). Whole-word match.
Mnemonic: * draws attention forward to "this word"; # is the mirror.
*
#
g* (substring match, not whole word)
:nohClear the highlighted search results (hlsearch).
Mnemonic: noh = no highlight.
:noh
:nohlsearch
:s/old/new/Substitute first match of "old" with "new" on the current line.
Mnemonic: :s = substitute.
:s/foo/bar/
:s/foo/bar/g (all on this line)
:s/old/new/gSubstitute every match of "old" with "new" on the current line.
Mnemonic: g flag = global within this line.
:s/foo/bar/g
:%s/old/new/gSubstitute every match in the WHOLE file. The workhorse find-and-replace.
Mnemonic: % = entire file, g = every occurrence on each line.
:%s/foo/bar/g
:%s/\<foo\>/bar/g (whole word only)
:%s/old/new/gcLike %s/g but with "confirm" — prompts y/n/a/q/l for each match.
Mnemonic: c flag = confirm each one.
:%s/foo/bar/gc
:<range>s/old/new/gSubstitute only inside a line range (e.g. 5,20 or visual selection '<,'>).
Mnemonic: Range before s narrows the scope.
:5,20s/foo/bar/g
:'<,'>s/foo/bar/g (visual selection)
gnSelect the next match of the last search pattern as a visual selection (operator-friendly: cgn changes it).
Mnemonic: gn = go to next match AND grab it.
cgn (change next match, then . to repeat)
dgn
:g/pat/dGlobal command: delete every line matching the pattern. The classic "remove all lines containing X".
Mnemonic: :g = run a command on every matching line; here d = delete.
:g/TODO/d
:g/^\s*$/d (delete blank lines)
:v/pat/dInverse global: delete every line that does NOT match the pattern (keep only matches).
Mnemonic: :v = :g! = act on lines that do NOT match.
:v/keep/d
:g!/error/d
:g/pat/normal @aRun a macro (or any normal command) on every line matching a pattern.
Mnemonic: :g + normal = batch a normal-mode command over matching lines.
:g/^func/normal @a
:g/foo/normal A;
:%s//new/gReuse the LAST search pattern in a substitute by leaving the pattern empty.
Mnemonic: Empty pattern in :s = "use my last /search".
/foo then :%s//bar/g
:s/.../\=expr/Use \= to evaluate a vim expression as the replacement (e.g. arithmetic on the match).
Mnemonic: \= turns the replacement into "compute this".
:s/\d\+/\=submatch(0)+1/ (add 1 to the number)
\v (very magic)Put \v at the start of a pattern so most characters are special — regex looks closer to PCRE (fewer backslashes).
Mnemonic: \v = very magic = "treat it like a real regex".
/\v(foo|bar)
:%s/\v(\w+)\s+\1/\1/g (collapse doubled words)
:sort / :sort uSort the lines in range (or whole file). Add u to remove duplicate lines, n for numeric, ! to reverse.
Mnemonic: sort = sort lines; u = unique, n = numeric, ! = reverse.
:sort
:sort u
:sort n
:%sort! (reverse sort all)
"a y<motion>Yank into named register "a" instead of the default register.
Mnemonic: Quote + letter = "use this register slot".
"ayy (yank line to register a)
"byw (yank word to register b)
"a pPaste from named register "a".
Mnemonic: Quote + letter + p = paste that register.
"ap
"bP (paste register b before cursor)
"+y / "+pYank to / paste from the system clipboard register (needs +clipboard build).
Mnemonic: + register = system clipboard.
"+yy (copy line to system clipboard)
"+p (paste from OS clipboard)
"* y / "* pYank/paste using the X11 PRIMARY selection (Linux middle-click).
Mnemonic: * register = PRIMARY (the selection one).
"*yy
"*p
"_ d<motion>Delete into the black-hole register — does NOT overwrite your clipboard / default.
Mnemonic: Underscore = "throw it away", black hole.
"_dd (delete line WITHOUT yanking)
"_x
:regShow all registers and their current contents.
Mnemonic: reg = registers list.
:reg
:reg a b "
"0 pPaste the last yank (register 0 is the yank-only register, unaffected by deletes).
Mnemonic: 0 = the yank-only slot, "rescue clipboard from deletes".
"0p
"A y<motion>Yank and APPEND to register a (uppercase register = append instead of overwrite). Great for collecting lines.
Mnemonic: Uppercase register letter = append to that register.
"Ayy (append this line to register a)
"Add
". pPaste from the "." register — the text you most recently typed in insert mode.
Mnemonic: . register = "the last thing I typed".
".p
"% pPaste the "%" register — the current file name (relative path).
Mnemonic: % register = current file name (like % in :commands).
"%p
:put % (put filename on a new line)
": pPaste the ":" register — the last Ex command you ran. Handy for re-editing a command.
Mnemonic: : register = the last : command.
":p
@: (re-run the last Ex command)
Ctrl+r Ctrl+w (cmdline)On the command line or search prompt, pull in the word under the cursor (Ctrl+r Ctrl+a pulls the WORD).
Mnemonic: Ctrl+r Ctrl+w = read the cursor word into the command line.
:s/<Ctrl+r Ctrl+w>/new/
/<Ctrl+r Ctrl+w>
:put <reg>Put the contents of a register on the line below the cursor (always line-wise, even for char-wise registers).
Mnemonic: :put = drop a register on its own line.
:put a
:put + (paste clipboard line-wise)
:0put a (put at top of file)
m<letter>Set a mark at the cursor with the given letter (a-z local, A-Z global across files).
Mnemonic: m = mark.
ma (mark a)
mZ (global mark Z)
'<letter>Jump to the LINE of mark <letter> (cursor lands at first non-blank).
Mnemonic: Single quote = "jump line".
'a
'A (jump to mark A across files)
`<letter>Jump to the exact LINE AND COLUMN of mark <letter>.
Mnemonic: Backtick = "jump exact".
`a
`A
:marksList all marks currently set.
Mnemonic: marks = list of marks.
:marks
:marks abc (just a, b, c)
''Jump back to the position before the last jump.
Mnemonic: '' = bounce back where you were.
''
:delmarksDelete marks. :delmarks a deletes mark a; :delmarks! clears all a-z local marks.
Mnemonic: delmarks = delete marks.
:delmarks a
:delmarks!
'< / '>Marks set automatically at the start / end of the last visual selection.
Mnemonic: '< and '> are the visual selection boundaries (used in :'<,'>).
'<
'>
:'<,'>s/foo/bar/g
'[ / ']Marks at the first / last line (or position with backtick) of the most recently changed or yanked text.
Mnemonic: '[ '] bracket the last change/yank region.
'[
']
`[v`] (reselect last pasted text)
``Jump to the exact position before the latest jump (column-precise version of the '' line jump).
Mnemonic: Two backticks = bounce back to the exact spot.
``
'"Jump to the position where the cursor was when you last closed this file (restored from viminfo/shada).
Mnemonic: '" = "take me back to where I left this file".
'"
au BufReadPost * normal! `" (auto-restore on open)
:sp [file]Split window horizontally (top/bottom). Open file if given.
Mnemonic: sp = split horizontally (think rows stacked).
:sp
:sp src/main.ts
:vsp [file]Split window vertically (left/right). Open file if given.
Mnemonic: vsp = vertical split.
:vsp
:vsp README.md
Ctrl+w h/j/k/lMove focus to the window on the left / below / above / right.
Mnemonic: Ctrl+w = window prefix, then hjkl direction.
Ctrl+w h
Ctrl+w l
Ctrl+w wCycle focus to the next window.
Mnemonic: Ctrl+w w = window-window = next.
Ctrl+w w
Ctrl+w =Make all windows equal size.
Mnemonic: = sign = make equal.
Ctrl+w =
Ctrl+w + / Ctrl+w -Grow / shrink current window height by one row.
Mnemonic: + grows, - shrinks. Same as everywhere.
Ctrl+w +
5 Ctrl+w + (grow by 5 rows)
Ctrl+w > / Ctrl+w <Grow / shrink current window width.
Mnemonic: > shifts right edge out, < shifts in.
Ctrl+w >
10 Ctrl+w >
Ctrl+w oMake the current window the only one — close all others.
Mnemonic: o = only.
Ctrl+w o
:only
Ctrl+w q / :qClose the current window.
Mnemonic: q = quit this window.
Ctrl+w q
:q
Ctrl+w s / Ctrl+w vSplit the current window horizontally (s) / vertically (v) — same as :sp / :vsp via the window prefix.
Mnemonic: Ctrl+w then s = split, v = vertical split.
Ctrl+w s
Ctrl+w v
Ctrl+w H/J/K/LMove the current window to the far left / bottom / top / right of the layout (rearranges splits).
Mnemonic: Capital HJKL with Ctrl+w = shove the whole window that direction.
Ctrl+w H (move window to far left)
Ctrl+w L
Ctrl+w rRotate the windows in the current row/column (swap their positions).
Mnemonic: Ctrl+w r = rotate windows.
Ctrl+w r
Ctrl+w R (rotate the other way)
Ctrl+w TMove the current window into its own new tab.
Mnemonic: Ctrl+w T = send this window to a Tab.
Ctrl+w T
Ctrl+w _ / Ctrl+w |Maximize the current window height (_) or width (|).
Mnemonic: _ is a flat bar = max height; | is a tall bar = max width.
Ctrl+w _
Ctrl+w |
Ctrl+w pJump to the previously focused window (toggle between two windows).
Mnemonic: Ctrl+w p = previous window.
Ctrl+w p
:ls / :buffersList all open buffers with their numbers.
Mnemonic: ls = list (like shell).
:ls
:buffers
:b <num|name>Switch to buffer by number or by (partial) filename.
Mnemonic: b = buffer.
:b 3
:b main.ts
:b# (go to alternate buffer)
:bn / :bpGo to the next / previous buffer.
Mnemonic: bn = buffer next, bp = buffer previous.
:bn
:bp
:bd <num|name>Delete (close) a buffer.
Mnemonic: bd = buffer delete.
:bd
:bd 3
:bd main.ts
:tabnew [file]Open a new tab (optionally with a file).
Mnemonic: tabnew = new tab.
:tabnew
:tabnew src/index.ts
:tabn / :tabpGo to the next / previous tab. gt / gT also work in normal mode.
Mnemonic: tabn = tab next, gt = go tab.
:tabn
:tabp
gt
gT
:tabcloseClose the current tab.
Mnemonic: tabclose = close tab.
:tabclose
:tabc
:e <file>Edit (open) a file in the current window.
Mnemonic: e = edit.
:e ~/.vimrc
:e %:h/<Tab> (browse same directory)
Ctrl+^Switch to the alternate buffer — the file you were in just before this one. Toggles between two files fast.
Mnemonic: Ctrl+^ = bounce to the other file (the # buffer).
Ctrl+^
:b#
:bufdo <cmd>Run an Ex command in every open buffer (e.g. a substitution across all files).
Mnemonic: bufdo = do this in every buffer.
:bufdo %s/foo/bar/ge | update
:bufdo set ff=unix
:windo <cmd>Run an Ex command in every window on the current tab.
Mnemonic: windo = do this in every window.
:windo set scrollbind
:windo diffthis
:tabdo <cmd>Run an Ex command in every tab page.
Mnemonic: tabdo = do this in every tab.
:tabdo windo set nu
:bufdo bd / :%bdClose all buffers at once. :%bd then Ctrl+^ Ctrl+w o is a common "close everything but this file" combo.
Mnemonic: %bd = delete every buffer (the % range covers them all).
:%bd
:%bd | e# (keep current, close rest)
:sb <num|name>Open a buffer in a new split instead of replacing the current window.
Mnemonic: sb = split + buffer.
:sb 3
:vert sb main.ts (vertical split buffer)
q<letter>Start recording a macro into register <letter>. Press q again to stop.
Mnemonic: q = quick record.
qa (start recording into a)
qa...q (record and stop)
@<letter>Play back the macro stored in register <letter>.
Mnemonic: @ = at-sign = "execute this register".
@a
100@a (repeat macro a 100 times)
@@Replay the last executed macro (no need to remember the letter).
Mnemonic: @@ = "do that again".
@@
50@@
:let @a = "..."Set a macro/register manually without recording. Handy for editing macros.
Mnemonic: let @a = "..." writes directly to register a.
:let @a = "ihello\<Esc>"
qA (append to macro)Record into an UPPERCASE register to append to an existing macro instead of overwriting it.
Mnemonic: Uppercase q-register = keep recording onto the end.
qA (append to macro a)
qA...q
Q (replay last @)In recent vim/neovim, Q replays the last used register macro (like @@). The old Ex-mode meaning was remapped.
Mnemonic: Q = repeat the last macro (newer default).
Q
:normal @a (over range)Apply a macro to a range of lines in one shot (no need to count repeats).
Mnemonic: :<range>normal @a = run macro a on each line in the range.
:5,20normal @a
:'<,'>normal @a
:let @A .= "..."Append to a register from the command line (.= concatenates) — useful for tweaking a recorded macro.
Mnemonic: .= appends; @A is the append form of register a.
:let @a .= "j"
:let @q = "0" . @q
zoOpen the fold under the cursor.
Mnemonic: z + o = open one fold.
zo
zcClose the fold under the cursor.
Mnemonic: z + c = close one fold.
zc
zaToggle the fold under the cursor (open if closed, close if open).
Mnemonic: a = alternate / toggle.
za
zROpen ALL folds in the buffer.
Mnemonic: Capital R = "Reveal everything".
zR
zMClose ALL folds (Maximum folding).
Mnemonic: Capital M = Maximum fold.
zM
:set fdm=<method>Choose folding method: manual / indent / marker / syntax / expr / diff.
Mnemonic: fdm = foldmethod.
:set fdm=indent
:set fdm=marker
:set fdm=syntax
zf<motion>Manually create a fold over the motion (works only with foldmethod=manual).
Mnemonic: zf = fold form / make.
zf3j (fold current + 3 lines below)
zfap (fold a paragraph)
zd / zEDelete the fold under the cursor (zd) / eliminate ALL folds in the buffer (zE). Manual folds only.
Mnemonic: zd = delete one fold, zE = eliminate every fold.
zd
zE
zj / zkMove to the start of the next fold (zj) / end of the previous fold (zk).
Mnemonic: z + j/k = move between folds, same down/up sense as j/k.
zj
zk
zr / zmReduce (zr) / increase (zm) the fold level by one — open or close one more layer of nested folds.
Mnemonic: zr = reduce folding (open a layer), zm = more folding.
zr
zm
zvOpen just enough folds to make the line with the cursor visible (view the cursor).
Mnemonic: zv = view the cursor line (unfold just enough).
zv
ziToggle folding on/off for the whole buffer (flips foldenable).
Mnemonic: zi = invert folding on/off.
zi
How do I exit vim?Press Esc, then type :q (quit). If you have unsaved changes use :wq (save and quit) or :q! (quit and toss changes).
Mnemonic: Esc + colon = leave the trap. q = quit, q! = quit forcefully.
:q
:wq
:q!
ZZ (= :wq)
ZQ (= :q!)
Pasting from clipboard mangles indentationVim auto-indents what you type — when you paste code from the OS, indentation cascades. Toggle :set paste before pasting, :set nopaste after.
Mnemonic: :set paste = "I am not typing, just pasting raw bytes".
:set paste
(paste your code)
:set nopaste
(better:) :set pastetoggle=<F2>
How do I undo? Where did Ctrl+z go?In normal mode, press u to undo, Ctrl+r to redo. Ctrl+z suspends vim to the shell (`fg` returns).
Mnemonic: u = undo (NOT Ctrl+z). Vim was designed before Windows/Mac standardized Ctrl+z.
u
Ctrl+r
:earlier 5m (undo back to 5 minutes ago)
:later 5m
Search keeps highlighting after I find itThat is hlsearch. Run :noh once to clear; map <leader>h to it for daily life.
Mnemonic: noh = no highlight. Common in every .vimrc.
:noh
nnoremap <leader>h :noh<CR>
"E37: No write since last change"You tried to switch buffers / quit without saving. Save with :w, force-discard with :e! / :q!, or :set hidden to allow background buffers with unsaved changes.
Mnemonic: E37 = "save first, or force with !".
:w
:q!
:set hidden
"E37: No write since last change" but I already saved!You probably hit Ctrl+s, which is XOFF (freezes terminal) in many terminals — vim never got the signal. Use :w instead, then Ctrl+q to unfreeze if needed.
Mnemonic: Ctrl+s = freeze terminal (XOFF), Ctrl+q = unfreeze (XON).
:w
stty -ixon (disable terminal flow control)
I opened a file with vim but it is read-onlyEither you opened with vim -R, or the file is owned by root. Workarounds: :w !sudo tee % > /dev/null to save through sudo, or :set noreadonly then :w! if you have perms.
Mnemonic: sudo-tee trick = pipe the buffer through sudo tee back to the file.
:w !sudo tee % > /dev/null
:set noreadonly | w!
Vim "started in REPLACE mode" / weird overwritingYou pressed Caps Lock + a or hit Insert twice. Esc + i puts you back in normal insert mode. Check :set showmode is on so you can see what mode you are in.
Mnemonic: Always glance at the status line — vim shows -- INSERT -- / -- REPLACE -- / -- VISUAL --.
Esc i
:set showmode
Why does dd "yank" instead of just deleting?In vim, delete IS cut — it puts the deleted text into the default register. To delete without yanking, use the black-hole register: "_dd.
Mnemonic: "_ + d = throw it away (no register pollution).
"_dd
"_x
nnoremap <leader>d "_d (map <leader>d to black-hole delete)
Swap file warning: ".file.swp" already existsAnother vim is editing the same file, or it crashed last time. Press R to recover, D to delete the swap, Q to quit. If you are sure no other process — `ls -la .file.swp` then delete.
Mnemonic: R = Recover, D = Delete swap, Q = Quit, A = Abort.
(R)ecover
(D)elete
rm .myfile.swp
I hit Ctrl+s and the whole terminal frozeCtrl+s sends XOFF, which freezes terminal output (vim looks dead but is fine). Press Ctrl+q (XON) to unfreeze. Add stty -ixon to your shell rc to disable this.
Mnemonic: Ctrl+s freezes (XOFF), Ctrl+q thaws (XON).
Ctrl+q
stty -ixon
I typed :W or :Q and got "E492: Not an editor command"You held Shift too long — :W and :Q are not commands. Use lowercase :w and :q. Many people add command! W w and command! Q q to their vimrc to forgive this.
Mnemonic: Commands are lowercase: :w :q :wq, not :W :Q.
:w
:q
command! W w
My arrow keys insert letters like A B C DA terminal in the wrong mode (or vi compatible mode) sends raw escape codes for arrows. Make sure your vimrc has set nocompatible, and prefer a real vim, not the bare "vi".
Mnemonic: set nocompatible fixes most "arrows type letters" weirdness.
set nocompatible
(or just use hjkl 😄)
I pasted code and indentation exploded into a staircaseAutoindent re-indents each pasted line on top of the previous one. Use :set paste first, paste, then :set nopaste. With system clipboard, "+p pastes verbatim and avoids this entirely.
Mnemonic: :set paste before pasting, or use "+p for raw clipboard paste.
:set paste
"+p
:set nopaste
I want to undo ALL my changes since opening the fileUse :e! to reload the file from disk and discard every unsaved change. (u only steps back one change at a time; :e! resets to the saved version.)
Mnemonic: :e! = re-edit, throwing away unsaved changes.
:e!
:edit!
How do I see line numbers / relative line numbers?Run :set number for absolute line numbers, :set relativenumber for distances from the cursor (makes 5j / 12k counts obvious). Combine both for a hybrid gutter.
Mnemonic: number = absolute, relativenumber = distance-based.
:set number
:set relativenumber
:set nu rnu
I selected text but Ctrl+c / Ctrl+v does not copy to other appsVim has its own registers; the OS clipboard is the + register. Yank with "+y (or "+yy for a line) and paste elsewhere; from outside, paste into vim with "+p. Needs a +clipboard vim build (check :version).
Mnemonic: OS clipboard = the "+ register, not the default register.
"+yy
"+p
:version (look for +clipboard)
My search is case-sensitive (or annoyingly case-insensitive)Set :set ignorecase to match any case, plus :set smartcase so an uppercase letter in the query forces case-sensitivity. For a one-off, append \c (insensitive) or \C (sensitive) to the pattern.
Mnemonic: ignorecase + smartcase is the sweet spot; \c / \C override per search.
:set ignorecase smartcase
/Foo\C
/foo\c
I keep landing in Ex mode with a colon prompt that will not leaveYou pressed Q (old binding) and entered Ex mode. Type visual then Enter (or :vi) to return to normal mode. Many configs remap Q to avoid this trap.
Mnemonic: Ex mode escape: type :vi (or visual) + Enter.
:vi
visual<CR>
A searchable vim cheat sheet built for people who actually live in the terminal. 122 commands across 11 categories: modes (normal / insert / visual / command / replace), motions (hjkl, w/b/e, gg/G, 0/^/$, paragraphs and sentences, half- and full-page scroll, screen positioning, find-on-line with f/F/t/T, matching brackets, jump list), edits (i/a/o/O, x/r/s, d/c/y + motion, p/P, u/Ctrl+r, the dot command, indent, case toggle, join, text objects with i/a), search & substitute (/, ?, n/N, * #, :s and :%s with g/c flags and ranges), registers ("ay "ap, the system clipboard "+, the X11 PRIMARY "*, the black-hole "_, the yank-only 0 register, :reg), marks (ma 'a `a :marks '' :delmarks), splits and windows (:sp :vsp, Ctrl+w h/j/k/l, Ctrl+w =, Ctrl+w + and >, Ctrl+w o and q), buffers and tabs (:ls :b :bn :bp :bd, :tabnew :tabn :tabp), macros (qa, @a, @@, :let @a = …), folds (zo zc za zR zM zf, foldmethod), and the famous "How do I exit vim?" pitfalls category (paste mangles indent → :set paste; Ctrl+s freezes terminal; "E37: no write since last change"; the dd-yanks-instead-of-deletes trap and the black-hole register fix; swap file recovery; replace mode surprise). Every entry has a command, an EN+ZH explanation, a short mnemonic so you actually remember it, and one or two real examples you can copy with the inline copy button. Search runs live across command, descriptions, mnemonics and examples — type "clipboard" and the "+ register pops up. Filter by category with a single click. Fully bilingual EN/ZH (native, not translated), 100% client-side, no tracking, no ads. Pair with our Git Cheatsheet, Regex Cheatsheet, Docker Cheatsheet and Kubectl Cheatsheet for the rest of the daily-Google syntax stack.
Paste or drop your content into the tool panel.
Click the button. All processing is local in your browser.
Copy the result or download to disk in one click.
Use it in the small gaps between coding, reviewing, debugging, and shipping.
These links move the current task into a more complete workflow.
You ran git commit, no -m, and now a blank vim buffer is staring at you over SSH. Press i, type your one-line message, hit Esc, then :wq and Enter. If you only meant to abort, :q! bails and git cancels the commit. Searching this sheet for "exit vim" gets you ZZ and ZQ too — the two keystrokes that save the most trips back here at 2am.
You SSH into a box, open /etc/nginx/nginx.conf, and "+y does nothing because the stock vim is built -clipboard. Filter to Registers, copy with yy into the unnamed register, navigate, then p. For getting a config block onto your laptop, visual-select with V, yank, and rely on your terminal's mouse selection — the sheet's clipboard entry spells out the +clipboard check and the OSC-52 fallback.
Instead of 40 manual edits, jump to the first hit with /oldName, change it with cw, type newName, Esc. Then press . on every next match — the dot command repeats the whole change. For a blind sweep, :%s/oldName/newName/gc replaces across the file and the c flag asks y/n at each of the 40 spots so you never clobber a substring you meant to keep.
Each line needs a timestamp stripped and a comma added. Record once: qa, do the edits on line one, q to stop. Then 199@a replays it down the file in one shot. Search this sheet for "macro" to get qa / @a / @@ and the :let @a trick for editing a macro that fumbled one keystroke — far faster than 200 hand edits.
Typing :q with unsaved changes and panicking at "E37" — it is not an error you broke, just add ! (:q!) to discard or use :wq to save.
Pasting from the browser without :set paste first, so autoindent cascades every line right; toggle :set paste before, :set nopaste after.
Assuming "+y works everywhere — run vim --version | grep clipboard first; a -clipboard build silently does nothing and you lose the yank.
This cheat sheet is a static reference that runs entirely in your browser. Your search queries and the category you filter to never leave the page — there is no backend call, no analytics on what you look up, and nothing is written to the URL. You can read it offline once the page has loaded.
Folks in your role tend to reach for these alongside this tool.