Editing a Macro
Paste it, fix it, yank it back. Macros are text.
Because a macro is just register contents, you can paste it into the buffer, edit any keystroke, and yank it back. This is how macros get refined without a full re-record.
Recording is the easy way to get a macro. But re-recording every time you want a small fix is painful. Faster: paste the macro into a scratch buffer, edit the keystrokes, yank it back. The macro is text.
The recipe
Suppose macro a is almost right but has a bug.
1. Open a scratch line: oEsc.
2. Paste the macro: "ap. The keystrokes appear as text.
3. Edit them โ replace dawi with daWi, fix a typo, whatever.
4. Select the corrected text (e.g. 0v$ or just place cursor at start) and yank it back into a: "ay$.
5. Undo the buffer changes (u, u) so the keystroke text doesn't pollute your file.
6. @a โ try the corrected macro.
| Key | Note |
|---|---|
| " | |
| a | |
| p |
| Key | Note |
|---|---|
| " | |
| a | |
| y | |
| $ |
See also: Recording and Playing Macros, Macros Are Just Register Contents, Named Registers