A practical Vim cheat sheet — the commands you'll use after the first hour, organized by what you're trying to do. Tested on Vim 8 and Neovim.
The modes
| Mode | Enter from Normal | What it's for |
| Normal | Esc from anywhere | Default; navigate + run commands |
| Insert | i a o O I A | Type text |
| Visual | v (char) V (line) Ctrl-v (block) | Select text |
| Command | : | Save, search, run external |
| Replace | R | Overwrite as you type |
Save & quit (Command mode)
| Command | Effect |
:w | Write (save) |
:w newname | Save as new name |
:q | Quit (errors if unsaved changes) |
:q! | Quit, discard changes |
:wq / :x / ZZ | Save + quit |
:e file | Open another file |
:e! | Reload current file from disk |
:qa / :qa! | Quit all buffers |
Motions (navigate without arrow keys)
| Key | Move |
h j k l | Left, down, up, right |
w / W | Next word / WORD (W ignores punctuation) |
b / B | Previous word / WORD |
e / E | End of word / WORD |
0 | Start of line |
^ | First non-whitespace on line |
$ | End of line |
gg | Top of file |
G | Bottom of file |
123G | Go to line 123 |
{ / } | Previous / next paragraph |
( / ) | Previous / next sentence |
% | Jump to matching bracket / paren / brace |
Ctrl-d / Ctrl-u | Half page down / up |
Ctrl-f / Ctrl-b | Full page down / up |
H M L | Top / middle / bottom of screen |
zz | Center current line on screen |
`` | Jump back to previous position (two backticks) |
Ctrl-o / Ctrl-i | Jump back / forward in jump list |
Insert mode entry
| Key | Effect |
i | Insert before cursor |
a | Insert after cursor |
I | Insert at start of line (first non-whitespace) |
A | Insert at end of line |
o | Open new line below + insert |
O | Open new line above + insert |
s | Delete char + insert |
S | Delete line + insert |
cc | Change line |
cw | Change word |
Operators (combine with motions)
Pattern: operator + motion. Example: d (delete) + w (word) = dw (delete word).
| Op | Means | Example |
d | Delete (cut) | d$ delete to end of line |
c | Change (delete + insert) | ciw change inner word |
y | Yank (copy) | yy yank line |
> / < | Indent right / left | >> indent line |
= | Auto-indent | gg=G auto-indent whole file |
~ | Toggle case | ~ toggle char |
gU / gu | Upper / lower case | gUw uppercase word |
Text objects (use with operators)
| Object | Means |
iw / aw | Inner word / a word (with surrounding space) |
i" / a" | Inside / around double quotes |
i' / a' | Inside / around single quotes |
i( / i) / ib | Inside parens |
i{ / i} / iB | Inside braces |
i[ / i] | Inside brackets |
i< / it | Inside angle brackets / HTML tag |
ip / ap | Paragraph |
is / as | Sentence |
Combine: ci" = change inside double quotes. dap = delete a paragraph. yi( = yank inside parens.
Copy / paste / undo
| Key | Effect |
yy / Y | Yank (copy) line |
p | Paste after cursor |
P | Paste before cursor |
"+y / "+p | Yank/paste from system clipboard |
u | Undo |
Ctrl-r | Redo |
. | Repeat last change (the killer feature) |
Search
| Key | Effect |
/pattern | Search forward |
?pattern | Search backward |
n / N | Next / previous match |
* / # | Search word under cursor forward / backward |
:noh | Clear highlight |
Replace
:s/old/new/ Replace first on line
:s/old/new/g Replace all on line
:%s/old/new/g Replace all in file
:%s/old/new/gc Replace all, confirm each
:%s/\<old\>/new/g Replace whole word only
:5,20s/old/new/g Replace in lines 5-20
Test patterns first with the regex tester — Vim's regex flavor is similar to PCRE with some quirks.
Visual mode
| Key | Effect |
v | Character-wise selection |
V | Line-wise selection |
Ctrl-v | Block-wise (column) selection |
o | Move cursor to other end of selection |
gv | Re-select last visual selection |
(after selecting) d y c > < ~ | Apply operator to selection |
Buffers, windows, tabs
| Command | Effect |
:ls | List buffers |
:b name | Switch to buffer by name |
:bn / :bp | Next / prev buffer |
:bd | Close buffer |
:split / :sp | Horizontal split |
:vsplit / :vs | Vertical split |
Ctrl-w h/j/k/l | Move between splits |
Ctrl-w = | Equalize splits |
Ctrl-w q | Close split |
:tabnew | New tab |
gt / gT | Next / prev tab |
Macros (record + replay)
qa Start recording macro into register a
... do stuff ...
q Stop recording
@a Play macro a
@@ Replay last macro
20@a Run macro 20 times
Useful one-shots
| Command | Effect |
:e . | Browse current directory |
:r file | Read file content into current buffer |
:r !date | Insert output of shell command |
:!cmd | Run shell command |
:set number / :set nonu | Toggle line numbers |
:set relativenumber | Relative line numbers (great with motions) |
:set ignorecase / :set smartcase | Case-insensitive search |
:syntax on | Syntax highlighting |
:set list | Show invisible characters (tabs, EOL) |
:retab | Convert tabs ↔ spaces per current settings |
Related tools
Test substitution patterns before using :%s/.../.../: regex tester. Compare two files line-by-line: diff checker.