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.
category: macros tags: #macros #registers #automation #editing
Next
How do I make buffer jumps prefer the last-used window that already shows the target buffer?
Related Tricks
How do I remove accidental Enter keystrokes from a recorded macro?
:let @q = substitute(@q, '\n', '', 'g')
How do I execute a macro from bottom to top over a selected range?
:'>,'<normal @q
How do I refactor a recorded macro by rewriting its keystrokes with substitute()?
:let @q = substitute(@q, 'foo', 'bar', 'g')
How do I append new keystrokes to an existing macro register without re-recording it?
:let @q .= 'A;<Esc>'
How do I run a one-off macro without recording by executing keystrokes from an expression register?
@='A;<Esc>'<CR>
