Vim Cheat Sheet
Essential Vim modal editing commands for navigation, editing, search-and-replace, and multi-file workflows.
Editing Commands
Deleting, copying, and changing text.
- dd / yy- Delete (cut) current line / yank (copy) current line
- p / P- Paste after cursor / paste before cursor
- x- Delete character under cursor
- cw- Change word: delete word and enter insert mode
- u / Ctrl-r- Undo / redo
- .- Repeat the last change
- v / V / Ctrl-v- Visual mode: character-wise, line-wise, block-wise selection
Search & Replace
Find text and substitute patterns.
:/pattern " Search forward for pattern:?pattern " Search backward for patternn / N " Repeat search forward / backward:%s/foo/bar/g " Replace all 'foo' with 'bar' in file:%s/foo/bar/gc " Same, with confirmation per match:s/foo/bar/g " Replace all occurrences on current line
Files & Windows
Saving, quitting, and splitting the view.
:w " Save:q " Quit:wq or :x " Save and quit:q! " Quit without saving:sp file.txt " Horizontal split:vsp file.txt " Vertical splitCtrl-w w " Cycle between split windows
Text Objects
Operate on syntactic chunks of text (word, quotes, brackets, tags) instead of raw motions.
diw " delete inner word (cursor anywhere in word)daw " delete a word, including trailing whitespaceci" " change inside double quotesca( " change around parentheses, including the parensdi{ " delete inside curly bracesdat " delete around an HTML/XML tagvip " visually select inner paragraphyi[ " yank inside square brackets" Pattern: [operator] + [i|a] + [object]" operators: d c y v objects: w s p " ' ( [ { t
Macros
Record a sequence of edits once and replay it across many lines.
qa " start recording into register a0dwjj " ...perform any sequence of edits...q " stop recording@a " replay the macro once10@a " replay the macro 10 times@@ " repeat the last-run macro:%normal @a " apply macro 'a' to every line in the file" Edit a recorded macro like text::let @a='0dwjj' " inspect/overwrite register a directly
Marks & Jump List
Bookmark positions and navigate your edit history across the file (or multiple files).
ma " set local mark 'a' at cursor position`a " jump to exact position of mark a'a " jump to start of line of mark amA " uppercase marks are GLOBAL, work across files`` " jump back to position before the last jumpCtrl-o / Ctrl-i " move backward / forward through the jump list:marks " list all active marksg; / g, " move through the change list (older/newer edit)
Registers & Advanced Substitution
Use named registers for multi-clipboard workflows and regex substitution with captured groups.
"ayy " yank current line into register a"ap " paste from register a"+y " yank into the system clipboard register:reg " list contents of all registers" Substitution with capture groups and case conversion::%s/\(\w\+\)@\(\w\+\)/\2@\1/g:%s/foo/\U&/g " uppercase every match ('&' = whole match):g/TODO/d " delete every line containing TODO:v/KEEP/d " delete every line NOT containing KEEP
Power-User Features
Editing at scale: multiple files, folding, and repeat-friendly workflows.
- :argdo %s/foo/bar/g | update- Run a substitution across every file in the arg list and save each
- zf / za / zR / zM- Create a fold, toggle it, open all folds, close all folds
- gv- Reselect the last visual selection
- Ctrl-a / Ctrl-x- Increment / decrement the number under the cursor
- :vimgrep /pat/ **/*.js- Recursively search files into the quickfix list for navigation with :cn/:cp
- q: - Open the command-line window to edit and rerun past Ex commands
- gq / gw- Reformat text to textwidth, moving or keeping the cursor respectively
Learn to combine operators with motions (e.g. d2w, ci", y$) instead of memorizing hundreds of commands — Vim's power comes from composing a small set of verbs and motions, not rote memorization.