All cheat sheets

Vim Cheat Sheet

Quick reference for Vim modes, movement, editing, search, and the commands developers use most.

Editors & Tools
vim
editor

Vim is a modal text editor with decades of muscle memory baked into its user base. Everything below assumes Vim 8+ or Neovim. The canonical reference is :help in-editor and vimhelp.org. For scripting, see Learn Vimscript the Hard Way.

Modes

Vim is modal: the same keys do different things in different modes.

Table
ModePurposeEnter from NormalReturn to Normal
NormalNavigation and commands(default)
InsertType text like a regular editori, a, o, etc.<Esc>, <C-[>
VisualSelect a regionv, V, <C-v><Esc>
Command-lineEx commands, search:, /, ?<Esc>
ReplaceOverwrite charactersR<Esc>

You spend most of your time in Normal mode. The single most important habit: hit <Esc> when in doubt.

Movement (Normal mode)

Table
KeyMoves
h j k lLeft, down, up, right (one char)
wForward to start of next word
bBackward to start of previous word
eForward to end of word
0Start of line
^First non-blank of line
$End of line
ggFirst line of file
GLast line of file
:nLine n
{ }Previous / next blank line (paragraph)
%Matching bracket / paren
Ctrl-dHalf-page down
Ctrl-uHalf-page up
Ctrl-fPage down
Ctrl-bPage up

Most commands accept a count: 5j moves down five lines, 3w advances three words.

Editing

Table
KeyAction
iInsert before cursor
aInsert after cursor
IInsert at start of line
AInsert at end of line
oOpen new line below and insert
OOpen new line above and insert
xDelete character under cursor
XDelete character before cursor
ddDelete line (and copy it)
dwDelete word
d$Delete to end of line
ccChange line (delete + insert)
cwChange word
yyYank (copy) line
ywYank word
p / PPaste after / before cursor
uUndo
Ctrl-rRedo
.Repeat last edit
>> / <<Indent / outdent line
JJoin next line with current

d, c, y are operators — they combine with a motion: d2w deletes two words, y$ yanks to end of line.

Search and replace

Table
CommandAction
/patternSearch forward
?patternSearch backward
n / NNext / previous match
* / #Search for word under cursor (forward / backward)
:s/old/new/Replace first match on current line
:s/old/new/gReplace all matches on current line
:%s/old/new/gReplace all matches in entire file
:%s/old/new/gcReplace with confirmation per match
:%s/old/new/gciConfirmation + case-insensitive

Useful flags on the substitute command:

Table
FlagMeaning
gAll occurrences in the line
cConfirm each replacement
iCase-insensitive
eSuppress "no match" errors
nReport count, do not replace

Visual selection

Table
KeySelects
vCharacter-wise selection
VLine-wise selection
Ctrl-vBlock (rectangular) selection

Once in visual mode, the same movement keys apply. d, c, y, > work on the selection. Block selection is great for column edits — e.g. add a prefix to several lines at once.

Search regex differences

Vim's default regex dialect ("magic") differs from PCRE / JavaScript. Most special characters (*, +, ?, (, ), {, }, |) must be backslash-escaped to be active. Prepend \v ("very magic") to a pattern to flip this: most characters become special without escaping, so patterns look much closer to PCRE.

Equivalent syntax in each dialect:

Table
FeaturePCRE / JavaScriptVim default (magic)Vim \v (very-magic)
Capture group(...)\(...\)(...)
One-or-more+\++
Optional?\? (or \=)?
Zero-or-more***
Word boundary\b\< and \>\< and \>
Lookahead/behind(?=...)not supportednot supported

Alternation uses a pipe between branches — escaped in Vim's default mode, plain under \v:

vim
" Vim magic: backslash the pipe. Matches "foo" or "bar".
:%s/foo\|bar/baz/g

" Vim very-magic: plain pipe, PCRE-like.
:%s/\vfoo|bar/baz/g

For complex patterns, \v is almost always clearer.

Windows and splits

Table
CommandAction
:sp[lit] fileHorizontal split with file
:vsp[lit] fileVertical split with file
Ctrl-w sSplit current buffer horizontally
Ctrl-w vSplit current buffer vertically
Ctrl-w h/j/k/lMove focus left / down / up / right
Ctrl-w H/J/K/LMove window to the far edge
Ctrl-w q / :qClose current window
Ctrl-w oClose all other windows (only this one)

Save and quit

Table
CommandAction
:wWrite (save) current buffer
:w fileWrite to file
:qQuit (fails if unsaved changes)
:wqWrite and quit
:xWrite if modified, then quit
:q!Quit, discarding unsaved changes
ZZSame as :x
ZQSame as :q!

Top 20 commands developers use

vim
i        " insert
Esc      " back to normal
:w       " save
:q!      " force quit
u        " undo
Ctrl-r   " redo
dd       " delete line
yy       " yank line
p        " paste
/pattern " search
n        " next match
:%s///g  " replace all in file
gg       " top of file
G        " bottom of file
0        " start of line
$        " end of line
w        " forward word
b        " backward word
.        " repeat last edit
:e file  " open file

Configuration tips

  • ~/.vimrc is loaded on startup. :set nocompatible then :set relativenumber puts line numbers relative to the cursor line, which pairs well with 5j-style counts.
  • syntax on enables syntax highlighting.
  • For plugin management, modern setups use vim-plug or Neovim's built-in :Lazy/:Packer.
  • Use :help keyword to look up any command from inside Vim — for example :help :substitute.

References