Macros (Recorded Keystrokes)
Record a sequence of keys and replay it to automate repetitive edits.
Code
" Record into register q
qa " start recording into q
0f,x " example: go to line start, find comma, delete it
jq " move to next line, stop recording
" Replay
@q " replay q once on current line
5@q " replay q 5 times
@@ " replay last used macro
:'a,'bnormal @q " run q on every line from mark a to b
:%normal @q " run q on every line in the file
" Editing a macro: paste the register, edit, yank back
:let @q = "0f,xj" " assign macro as a string
"ip " insert register i contents for editing
" Recursive macros (end with @q to loop) — useful but advancedExplanation
Macros turn repetitive edits into one keystroke. q followed by a register name (a–z) starts recording; q again stops. Replay with @register. @@ repeats the last. For ranges, use :'<,'>normal @q on a visual selection, or :%normal @q for the whole file. Because macros live in registers, you can paste them with "qp, edit the text, then yank back with "qy to refine. End macro lines with j so they advance; if a motion fails (e.g. f, finds no comma) the macro aborts — which is often desirable for stopping at EOF.
More Vim Snippets
Buffers, Windows & Tabs
Edit multiple files with buffers, split windows, and tab pages.
Search & Substitute
Find text with / and replace with :s, leveraging regex and ranges.
Registers (Multi-Clipboard)
Store yanks/deletes in named registers and paste from them.
Marks (Bookmarks)
Jump back to positions in a file or across files with marks.
Folding (Collapse Code)
Hide regions of code to focus on structure with fold methods.
Plugin Managers & Ecosystem
Install, configure and discover plugins with vim-plug / packer / lazy.