Vim Cheat Sheet
A reference for the Vim editor, modes, moving around, editing, search and replace, and saving or quitting, including the escape hatch for when you are stuck.
Vim is modal: keys do different things depending on the mode. Press Esc to
return to Normal mode, where these commands work. The golden rule if you
are stuck: press Esc, then type :q! and Enter to quit
without saving.
Modes
| Key | Enters |
|---|---|
| Esc | Normal mode (navigate, run commands) |
| i / a | Insert before / after the cursor |
| o / O | Open a new line below / above |
| v / V | Visual (character / line) selection |
| Ctrl+v | Visual block selection |
| : | Command-line mode |
Moving around
| Key | Moves to |
|---|---|
| h j k l | Left, down, up, right |
| w / b | Next / previous word |
| 0 / $ | Start / end of line |
| gg / G | First / last line of the file |
| :N | Go to line number N |
| Ctrl+d / Ctrl+u | Half page down / up |
Editing
| Key | Action |
|---|---|
| x | Delete the character under the cursor |
| dd / yy | Delete (cut) / yank (copy) the line |
| dw / cw | Delete / change to end of word |
| p / P | Paste after / before the cursor |
| u | Undo (Ctrl+r to redo) |
| . | Repeat the last change |
| N + command | Repeat N times (e.g. 3dd deletes 3 lines) |
Search & replace
| Command | Action |
|---|---|
/text | Search forward (?text backward) |
| n / N | Next / previous match |
:%s/old/new/g | Replace all occurrences in the file |
:%s/old/new/gc | Replace all, confirming each one |
Saving & quitting
| Command | Action |
|---|---|
:w | Save (write) the file |
:wq or ZZ | Save and quit |
:q | Quit (fails if there are unsaved changes) |
:q! | Quit and discard all changes |
:wqa | Save and quit all open windows |
Vim's power is in combining a count, an operator, and a motion, for
example d (delete) + 2 + w deletes two words. Run
vimtutor in a terminal for a hands-on 30-minute lesson.
What this does
A Vim cheat sheet covers modes, moving around, editing, search and replace, and saving or quitting — including how to exit when you are stuck.
How to use it
- Browse by task.
- Find the keystrokes you need.
- Copy any command with one tap.
- Practise in your own file.
Example
Press Esc, then :wq to save and quit.
Sources & methodology
Last updated .
Frequently asked questions
How do I exit Vim?
Press Esc, then type :q! and Enter to quit without saving, or :wq to save and quit. ZZ also saves and quits.
Why does typing not insert text?
Vim starts in Normal mode, where keys run commands. Press i to enter Insert mode and type, then press Esc to return to Normal mode.
How can I learn Vim properly?
Run vimtutor in a terminal, it is a built-in, hands-on lesson that takes about 30 minutes and covers the fundamentals.
Related tools
Git Cheat Sheet
The Git commands you use every day, setup, the add/commit/push workflow, branching and merging, working with remotes, and undoing mistakes safely.
Docker Cheat Sheet
A reference for everyday Docker, building and tagging images, running and managing containers, ports and volumes, system cleanup, and Docker Compose.
Regex Cheat Sheet
A regular-expression reference, character classes, anchors, quantifiers, groups and alternation, lookarounds, common ready-made patterns, and flags.
SQL Cheat Sheet
A reference for standard SQL, querying with SELECT, filtering with WHERE, aggregates and GROUP BY, joining tables, and modifying data and schema.