macro
q / @
q{register} starts recording a macro into that register; press q again to stop. Play it back with @{register}, and repeat the last macro with @@. Macros are just recorded keystrokes — anything you can do by hand, you can automate.
q{register} … q @{register} (normal mode) Variations
| Keystroke | Effect |
|---|---|
| @@ | Replay the last executed macro |
| 10@a | Run macro 'a' ten times |
| qA | APPEND further keystrokes to existing macro in register a |
| :reg a | Show the raw contents of register a (view/edit your macro) |
Examples
qaIfoo <Esc>jq Record macro 'a': insert 'foo ' at line start, go down
10@a Apply macro 'a' to the next 10 lines
@@ Repeat the last macro one more time
Gotcha
If your macro navigates with j/l and hits a short line, it can fail silently or land in the wrong spot — write macros with 0/$/w for reliable anchoring.
Related
.
Repeats the last CHANGE (any command that modified the buffer, including the whole insert-mode session that followed it). The single most-loved Vim feature — learn to structure edits so that '.' does the work for the next N occurrences.
yy
'Yank' (copy) the current line into the unnamed register — Vim's word for copy. Combine with p/P to duplicate lines without touching your system clipboard.
:!
:! runs a shell command and shows its output; with a range, :[range]!cmd pipes those lines through cmd and REPLACES them with its output. The bridge from Vim to the rest of your Unix toolbox.