Macros Are Just Register Contents
"ap โ edit โ "ay$ โ the macro lifecycle as text editing.
A recorded macro is text in a register. Paste it, edit it, yank it back. This unification of macros and clipboard text is one of Vim's smartest design choices.
qaโฆq records a macro into register a. @a plays it. But the register a is the same a you yank text into โ so the macro is just text. Which means you can edit it like any other text.
The lifecycle
A typical refinement loop looks like:
1. Record a draft: qaโฆq.
2. It mostly works but has a glitch.
3. o (open a new line), then "ap โ the keystrokes appear as text in the buffer.
4. Edit them. Maybe dawi should have been daWi. Replace.
5. "ay$ (yank from cursor to end of line back into register a) or "ayy for the whole line.
6. u to undo the buffer changes (you don't want the keystroke text staying in your file).
7. @a โ try the macro again with the fix.
| Key | Note |
|---|---|
| " | |
| a | |
| p |
| Key | Note |
|---|---|
| " | |
| a | |
| y | |
| $ |
| Key | Note |
|---|---|
| @ | |
| a |
See also: Registers, Named Registers, Recording and Playing Macros, Editing a Macro