Vim Cheat Sheet
A searchable Vim cheat sheet: modes, saving and quitting, motions, editing with operators and text objects, search and replace, visual mode, macros and splits.
Free · No sign-up · Your inputs stay in your browser
Reference
Vim cheat sheet
| Keys | Does |
|---|---|
| i a o | Insert before cursor, after it, on a new line below |
| Esc | Back to normal mode |
| :w :q :wq :q! | Save, quit, save and quit, quit without saving |
| :x or ZZ | Save if changed and quit |
| h j k l | Left, down, up, right |
| w b e | Next word, previous word, end of word |
| 0 ^ $ | Line start, first non-blank, line end |
| gg G 42G | First line, last line, line 42 |
| Ctrl-d Ctrl-u | Half page down, up |
| % | Jump to the matching bracket |
| dd yy p P | Delete line, copy line, paste after, paste before |
| dw d$ diw di" | Delete word, to end of line, inner word, inside quotes |
| ciw ci( cit | Change inner word, inside parentheses, inside a tag |
| x r | Delete character, replace character |
| u Ctrl-r | Undo, redo |
| . | Repeat the last change |
| v V Ctrl-v | Visual by character, by line, block |
| >> << | Indent, unindent |
| /text n N | Search forward, next, previous |
| * # | Search the word under the cursor |
| :%s/old/new/gc | Replace in the whole file, asking each time |
| :noh | Clear search highlighting |
| :set number | Line numbers (:set nu!) |
| :set paste | Paste without auto-indent (not needed in Vim 8+ with bracketed paste) |
| qa ... q @a | Record a macro in register a, then play it |
| 10@a | Play it ten times |
| :e file | Open a file |
| :sp :vs | Split horizontally, vertically |
| Ctrl-w w | Move between splits |
| :w !sudo tee % | Save a file you opened without sudo (Vim only; Neovim needs a plugin) |
| :r !command | Insert a command's output |
| gg=G | Re-indent the whole file |
| Ctrl-v j j I# Esc | Comment out lines with a block insert |
Normal-mode keys unless they start with a colon. Commands compose: an operator (d, c, y), an optional count and a motion (w, $, iw, it), so d3w deletes three words. The same keys work in Neovim and in the Vim modes of VS Code and JetBrains IDEs.
About this tool
Method, assumptions, practical next steps, and limits.
The grammar of Vim
Vim commands compose: an operator (d delete, c change, y copy), an optional count and a motion or text object (w word, $ end of line, iw inner word, i( inside parentheses). Once that clicks, d3w, ci" and yap need no memorising. Vim's built-in :help and the vimtutor command are the best teachers; the online Vim help mirrors them.
On servers
vi or vim is on almost every server, so a few commands go a long way: editing a config over SSH, fixing a crontab, resolving a merge conflict. Neovim and editor Vim modes accept the same keys.