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
qas 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:
- Press
qQto enter append mode for registerq - Press
wto move to the next word - Press
qto stop recording
Your macro now performs viw~w. Verify with :reg q to inspect the macro contents.
Tips
- Works with any register
a-z:qBappends to registerb,qZappends to registerz, etc. - If the register is empty, uppercase recording behaves identically to lowercase
- Combine with
:reg qto inspect the macro before and after appending