env.dev

Vim Cheat Sheet — Commands & Motions Quick Reference

Vim quick reference: modes, navigation, editing, search/replace, visual mode, registers, macros, and window management.

Last updated:

A quick reference for Vim commands. Covers modes, navigation, editing, search/replace, visual mode, registers, macros, and window management.

Modes

KeyDescription
EscReturn to Normal mode
iInsert mode (before cursor)
aInsert mode (after cursor)
vVisual mode (character selection)
VVisual Line mode (line selection)
Ctrl+vVisual Block mode (column selection)
:Command-line mode
RReplace mode (overwrite text)

Navigation

KeyDescription
h / j / k / lLeft / down / up / right
w / bNext word / previous word
eEnd of current word
0 / $Start / end of line
^ First non-blank character of line
gg / GGo to first / last line
:<number>Go to line number
Ctrl+d / Ctrl+uHalf-page down / up
Ctrl+f / Ctrl+bFull page down / up
%Jump to matching bracket

Editing

KeyDescription
i / aInsert before / after cursor
I / AInsert at start / end of line
o / ONew line below / above
ddDelete (cut) current line
dwDelete word from cursor
d$ / DDelete to end of line
yyYank (copy) current line
ywYank word from cursor
p / PPaste after / before cursor
u / Ctrl+rUndo / redo
xDelete character under cursor
r<char>Replace character under cursor

Search & Replace

CommandDescription
/patternSearch forward for pattern
?patternSearch backward for pattern
n / NNext / previous match
*Search for word under cursor
:s/old/new/Replace first on current line
:s/old/new/gReplace all on current line
:%s/old/new/gReplace all in entire file
:%s/old/new/gcReplace all with confirmation

Visual Mode

KeyDescription
vStart character-wise selection
VStart line-wise selection
Ctrl+vStart block-wise selection
dDelete selected text
yYank selected text
>Indent selected lines
<Unindent selected lines
gqReformat selected text

Registers & Macros

CommandDescription
"ayYank into register a
"apPaste from register a
:regShow all register contents
"+ yYank to system clipboard
qaStart recording macro into register a
qStop recording macro
@aPlay macro from register a
@@Replay last macro

Window Management

CommandDescription
:sp fileHorizontal split
:vsp fileVertical split
Ctrl+w h/j/k/lMove between splits
Ctrl+w =Equalize split sizes
Ctrl+w _Maximize current split height
Ctrl+w |Maximize current split width
:tabnew fileOpen file in new tab
gt / gTNext / previous tab

Common Commands

CommandDescription
:wSave file
:qQuit (fails if unsaved changes)
:wq / :xSave and quit
:q!Quit without saving
:e fileOpen file for editing
:set numberShow line numbers
:set pasteEnable paste mode (no auto-indent)
.Repeat last change

Frequently Asked Questions

What are the main Vim modes?

Normal mode (default, for commands), Insert mode (i/a/o, for typing), Visual mode (v/V/Ctrl-v, for selecting), and Command mode (:, for ex commands). Press Esc to return to Normal mode.

How do I search and replace in Vim?

Use :%s/old/new/g to replace all occurrences in the file. Remove % to replace only in the current line. Add c flag for confirmation: :%s/old/new/gc.

How do I save and quit in Vim?

:w saves the file. :q quits. :wq saves and quits. :q! quits without saving. ZZ is a shortcut for :wq. ZQ is a shortcut for :q!.