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

How do I append more commands to an existing macro without re-recording it from scratch?

Answer

qQ

Explanation

Recording a macro with an uppercase register letter appends to the existing macro in the corresponding lowercase register instead of overwriting it. This means you can extend a macro you have already recorded without starting over.

How it works

  • q{a-z} starts recording a new macro, overwriting register {a-z}
  • q{A-Z} starts recording in append mode to register {a-z}
  • Recording ends with q as usual

To append to a macro stored in register q, press qQ. For register a, press qA, and so on.

Example

Suppose you have a macro in register q that uppercases a word: viw~. You realize you also want it to advance to the next word with w.

Instead of re-recording the whole thing:

  1. Press qQ to enter append mode for register q
  2. Press w to move to the next word
  3. Press q to stop recording

Your macro now performs viw~w. Verify with :reg q to inspect the macro contents.

Tips

  • Works with any register a-z: qB appends to register b, qZ appends to register z, etc.
  • If the register is empty, uppercase recording behaves identically to lowercase
  • Combine with :reg q to inspect the macro before and after appending

Next

How do I refresh the diff highlighting in Vim when it becomes stale after editing?