How do I programmatically extend or modify a recorded macro without re-recording it?
:let @a = @a . "\<CR>extra"
Vim stores macros as plain text in registers — the same registers used for yanked text.
:let @a = @a . "\<CR>extra"
Vim stores macros as plain text in registers — the same registers used for yanked text.
<C-r>=strftime('%Y-%m-%d')<CR>
The expression register ("=) lets you evaluate any Vimscript expression and insert its result inline.
registers #registers #insert-mode #expression-register #dates
qQ
Recording a macro with an uppercase register letter appends to the existing macro in the corresponding lowercase register instead of overwriting it.
:let @q = @a . @b
Macros in Vim are stored as plain text in named registers.
reg_recording() and reg_executing()
Vim exposes two built-in functions for querying the current macro state: regrecording() and regexecuting().
:call setreg('q', 'dd')
The setreg() VimScript function lets you populate any register with arbitrary content directly from the command line or a script — no recording required.
zp
Pastes a blockwise register like p, but skips padding lines shorter than the block's right edge with trailing spaces.
:call setreg('q', keys, 'c')
The setreg() function writes any string directly into a named register, letting you construct macro keystrokes from Vimscript expressions rather than live recor
:let @a = @"
Vim's :let command lets you read and write register contents as strings, making it possible to copy, combine, or modify register values without ever leaving the
qq{actions}@qq
A recursive macro ends by calling itself, so it loops automatically without you pressing @q repeatedly.
<C-r>-
In insert mode, - pastes the contents of the small delete register ("-).
@q (inside macro recording)
A recursive macro calls itself as its last action, causing it to repeat indefinitely until it hits an error (like reaching end of file or failing a search).
{visual}p
When you visually select text and press p, Vim replaces the selection with the contents of the default register and saves the replaced text into the unnamed reg
qq{cmds}@qq
A recursive macro is one that calls itself at the end of its own body.
:put ={expr}
The :put ={expr} command evaluates a Vimscript expression and inserts the result as a new line below the cursor.
:let @+=@%
The % register always holds the name of the current file (as a relative path).
qa{actions}@aq
A recursive macro is one that calls itself as its final action, causing it to repeat indefinitely until any command in the body fails (e.
<C-r><C-r>{reg}
When you insert a register with {reg} in insert mode, Vim processes the content as if you had typed it — this means autoindent, autoformat, and insert-mode ma
:let @q = @:
The : register always holds the last Ex command you ran.
qqq
Pressing qqq in normal mode is the quickest way to empty a macro register.