vimtricks.wiki Concise Vim tricks, one at a time.

How do I edit a recorded macro?

Answer

"ap, edit, "add

Explanation

Since macros are stored in registers, you can paste the register content into the buffer, edit it, and yank it back. This lets you fix mistakes in recorded macros.

How it works

  1. "ap — paste register a (the macro) into the buffer
  2. Edit the keystrokes as needed
  3. "add — yank the edited line back into register a
  4. Run the fixed macro with @a

Example

You recorded a macro in q that has a typo. Paste it with "qp, fix the error, then "qdd to store it back.

Tips

  • :let @a = "edited macro content" also works for setting macro content
  • Special keys appear as ^[ (Escape), ^M (Enter), etc.
  • Use <C-v><Esc> to insert a literal Escape character
  • This technique is essential for complex macro development
  • Consider editing in a scratch buffer to avoid disrupting your work

Next

How do you yank a single word into a named register?