← Workbench
Workbench · reference sheet
Vim cheat sheet
The grammar: [count] verb + motion/object — d y c are verbs; w $ ap i" are objects. Esc always returns to Normal mode.
Last updated
theme
Project workflow
vim . | open file browser (netrw) in project dir |
| Enter | open file / expand dir |
| - | go up one directory |
| % | new file here |
| d / D | new dir / delete |
| R | rename |
:Ex | back to browser from a file |
Files & buffers
:e path | open file (Tab completes) |
| Ctrl-^ | toggle two most recent files |
:ls | list open buffers |
:b main | switch buffer by partial name |
| Ctrl-o / Ctrl-i | jump back / forward in history |
Save / quit
:w | save |
:wq / ZZ | save and quit |
:q! | quit without saving |
:qa | quit all windows |
Move
| h j k l | ← ↓ ↑ → |
| w / b | next / prev word |
| 0 / $ | start / end of line |
| gg / G | top / bottom of file |
42G or :42 | go to line 42 |
| Ctrl-d / Ctrl-u | half-page down / up |
| { / } | prev / next blank line |
| % | matching bracket |
| fx / ; / , | jump to char x on line / repeat / reverse |
Relative numbers in the gutter tell you the count: see 7 next to a line → 7j jumps there.
Insert
| i / a | insert before / after cursor |
| I / A | insert at start / end of line |
| o / O | open new line below / above |
Esc back to Normal mode — always.
Select (visual)
| v | select by character |
| V | select whole lines |
| Ctrl-v | select a block / columns |
| gv | reselect last selection |
Any selection takes a verb: y d c > ~.
Copy (yank) & paste
| yy / 5yy | copy line / 5 lines |
| p / P | paste below / above |
| yw / y$ | copy word / to end of line |
| V…y | select lines, then copy |
| "0p | paste the last yank — even after deletes |
| "+y / "+p | yank to / paste from system clipboard |
With clipboard=unnamedplus, plain yank/paste shares the system clipboard.
Delete (= cut)
| dd / 5dd | delete line / 5 lines |
| dw / D | delete word / to end of line |
| x | delete character |
| dap | delete paragraph/block |
| V…d | select lines, then delete |
:10,25d | delete lines 10–25 |
Deleted text lands in the paste register — delete + p = cut/paste.
Comment / uncomment block
| Ctrl-v | block-select col 1, j down |
I# Esc | prefix lands on every line |
| Ctrl-v…d | uncomment: select the # column, delete |
Range version: :10,20s/^/# / comments, :10,20s/^# // uncomments.
Search & replace
/foo | search (n next, N prev) |
| * | search word under cursor |
:noh | clear highlighting |
:%s/old/new/g | replace in whole file |
:%s/old/new/gc | …confirm each match |
:'<,'>s/…/g | replace in visual selection |
Search across files
:vimgrep /foo/ **/*.ts | search the project into the quickfix list |
:copen | open the results list |
:cn / :cp | next / prev result |
Undo / redo / repeat
| u | undo |
| Ctrl-r | redo |
| . | repeat last change (huge) |
Power moves
| ciw | replace word under cursor |
| ci" / ci( | replace inside quotes / parens |
| cc | replace whole line |
| rx | replace one character |
| J | join line below |
| >> / << | indent / dedent |
| =ap | auto-reindent paragraph |
| ~ | toggle case |
Splits
:sp / :vsp f | horizontal / vertical split |
| Ctrl-w h/j/k/l | move between splits |
| Ctrl-w o | close all others |
:q | close current split |
Odds & ends
vim +42 f | open at line 42 |
:!make check | run shell command |
:r !date | insert command output |
| qa…q, @a | record macro, replay (10@a ×10) |
| ma / `a | set mark a / jump to it |
| `` | back to where you jumped from |
:h subject | the real docs (Tab completes) |
Esc :q! | escape hatch from anything |