How do I append keystrokes to a macro without re-recording it?
Answer
:let @q .= 'j'
Explanation
Re-recording a long macro just to add one extra keystroke is wasteful and error-prone. Vim lets you treat macro registers as editable strings, so you can patch them in place. :let @q .= 'j' appends one normal-mode j motion to macro q, preserving everything you already recorded.
How it works
@qreferences the contents of registerq(your macro body).=is string concatenation assignment (append)'j'is the literal keystroke you want to add at the macro tail
Because macros are just register text, you can also prepend, replace fragments, or build them programmatically with more :let expressions.
Example
Assume macro q currently does:
f,ct,
That edits CSV fields but leaves the cursor on the same line. Append a line move:
:let @q .= 'j'
Now each replay of @q edits a field and moves down, making it usable in repeated batch workflows.
Tips
- Inspect the macro first with
:register q. - For special keys, append escaped keycodes (for example, carriage return) rather than plain text.
- If a change goes wrong, keep a backup first:
:let @a = @q, edit@q, and restore from@aif needed.