How do I append extra keystrokes to a recorded macro from the command line without re-recording it?
Answer
:let @q .= "j^"
Explanation
Live macro recording is fast, but adjusting the tail of a macro by re-recording can be risky once it already works in most places. :let @q .= "j^" appends keystrokes directly to register q, letting you extend an existing macro surgically. This is especially useful when you discover a missing navigation step after testing the macro across many lines.
How it works
@qreferences the contents of macro registerq.=appends text to the existing register value instead of replacing it"j^"adds two Normal-mode keystrokes:j(next line) then^(first non-blank)- The next
@qexecution includes both original and appended steps
Example
Imagine register q already contains a working edit for the current line, but you realize it should also move to the next line and align at indentation before repeating. Instead of recording again:
:let @q .= \"j^\"
Now running @q performs the old edit and then positions the cursor for a cleaner repeat cycle.
Tips
- Use
:echo string(@q)before and after edits to confirm exact macro contents - If you need to insert special keys (like
<Esc>), add them with escaped forms and test on a scratch buffer first - Prefer this approach when a macro is mostly correct and only needs small deterministic suffix changes