Vim Keyboard Shortcuts Cheat Sheet
A reference for Vim modal editing covering movement, editing commands, search and replace, and buffer management.
Modes
Vim's core editing modes and how to switch between them.
- Normal mode- Default mode for navigation and commands; press `Esc` to return to it
- Insert mode- `i` insert before cursor, `a` after cursor, `o` open new line below
- Visual mode- `v` character-wise, `V` line-wise, `Ctrl-v` block-wise selection
- Command-line mode- `:` enters commands like `:w`, `:q`, `:%s/foo/bar/g`
- Replace mode- `R` overtypes existing characters instead of inserting
Movement
Cursor navigation commands in normal mode.
h j k l # left, down, up, rightw / b # next word start / previous word starte # end of word0 / $ # start / end of line^ # first non-blank charactergg / G # top / bottom of file{n}G # go to line n% # jump to matching bracketCtrl-d / Ctrl-u # half page down / up
Editing
Common editing commands and operators.
x # delete character under cursordd # delete (cut) current lineyy # yank (copy) current linep / P # paste after / before cursoru / Ctrl-r # undo / redocw # change to end of wordd$ # delete to end of line>> / << # indent / unindent line. # repeat last change
Search & Replace
Finding and substituting text.
/pattern # search forward?pattern # search backwardn / N # repeat search same / opposite direction:%s/old/new/g # replace all occurrences in file:%s/old/new/gc # replace with confirmation* # search word under cursor forward
Files & Buffers
Saving, quitting, and managing multiple files.
- :w- Write (save) the current file
- :q / :q!- Quit / quit without saving
- :wq or :x- Save and quit
- :e filename- Open another file for editing
- :bn / :bp- Switch to next / previous buffer
- :sp / :vsp- Split window horizontally / vertically
Registers
Named storage slots for yanked and deleted text beyond the default clipboard.
"ayy # yank current line into register a"ap # paste from register a"+y # yank into system clipboard"+p # paste from system clipboard":reg # list all register contents".p # paste contents of the '.' (last insert) register"0p # paste last yank (unaffected by later deletes)
Macros
Recording and replaying a sequence of commands.
qa # start recording into register a... edits ... # perform the commands to repeatq # stop recording@a # replay macro a once5@a # replay macro a 5 times@@ # replay the last-run macro again
Marks & Jumps
Bookmarking positions and navigating the jump/change history.
ma # set mark a at cursor position`a # jump to exact position of mark a'a # jump to start of line containing mark aCtrl-o / Ctrl-i # go back / forward in jump listg; / g, # go to older / newer change location`` # jump back to position before last jump
Text Objects
Semantic units an operator can act on, independent of exact cursor position.
diw / daw # delete inner word / a word (with surrounding space)di" / da" # delete inside / around double quotesdi( / di{ # delete inside parentheses / bracescit # change inner tag content (HTML/XML)dap # delete a paragraphvi{ # visually select inside braces
Advanced Workflow
Configuration and features that separate proficient Vim usage from basic editing.
- :set expandtab / :set sw=4- Use spaces instead of tabs, and set shiftwidth for indentation
- Ex ranges- `:5,10d` deletes lines 5-10; `:.,$d` deletes from cursor to end of file; `:'<,'>` targets the last visual selection
- gq- Reformat/wrap text to `textwidth` over a motion or selection
- Ctrl-a / Ctrl-x- Increment / decrement the number under the cursor (great with a `g Ctrl-a` visual block for sequences)
- :g/pattern/d- Global command: delete every line matching pattern across the file
- zf / za- Create a fold over a motion / toggle fold open-closed
- :vimgrep /pat/ **/*.js- Search across multiple files and populate the quickfix list; navigate with `:cn` / `:cp`
Combine an operator with a text object for precise edits, e.g. `di"` deletes inside quotes and `ci(` changes inside parentheses — far faster than manually selecting text.