How do I detect whether a macro is currently being recorded or executed in Vimscript?
reg_recording() and reg_executing()
Vim exposes two built-in functions for querying the current macro state: regrecording() and regexecuting().
351 results for "registers"
reg_recording() and reg_executing()
Vim exposes two built-in functions for querying the current macro state: regrecording() and regexecuting().
{N}@q
Prefix a macro invocation with a count to execute it up to N times in a single command.
:s/pattern/\=expr/g
Vim's :s command normally replaces matches with a literal string.
command-line #search #editing #ex-commands #command-line #registers
:let @q = '{keystrokes}'
You can assign a string directly to any register using :let @{reg} = '.
:let @a = substitute(@a, "old", "new", "g")
When a recorded macro has a typo or wrong command buried inside it, you don't have to re-record the entire thing.
"qp {edit} 0"qy$ dd
When you record a macro and realize it has a mistake, the easiest fix is to paste the macro's keystrokes as text, edit them, and yank the corrected version back
<C-r>0
In Insert mode, {reg} pastes the contents of any register inline at the cursor.
<C-r><C-o>
When you paste a register in insert mode with {reg}, Vim inserts the text as if you had typed it — which means auto-indent, abbreviation expansion, and other
registers #registers #insert-mode #paste #autoindent #editing
@q
A recursive macro is a macro that calls itself as its last step, causing it to loop automatically until an operation fails (such as reaching the end of the file
<C-r><C-o>{reg}
When you use a in insert mode to paste register a, Vim inserts the text as if you typed it character by character.
5@q
Prefix the @ macro-execution command with a count to run the macro that many times in a row.
:let @q = @:
The : register always holds the last Ex command you ran.
:put ={expr}
The :put ={expr} command evaluates a Vimscript expression and inserts the result as a new line below the cursor.
qq{commands}@qq
A recursive macro calls itself at the end of its own definition, causing it to run repeatedly until Vim hits an error — such as reaching the end of the file o
:let i=0 | g/pattern/s/pattern/\=printf('%d', i+=1)/
By combining :let, the :g global command, and an expression substitution with \=, you can replace every match of a pattern with a unique incrementing number.
"0p in visual mode
When you paste over a visual selection with p, Vim replaces the selection with the register contents — but it also puts the deleted selection into the unnamed
P (in visual mode)
When you paste over a visual selection using p (lowercase), Vim replaces the selection with your register contents — but the replaced text overwrites your unn
qaq qa...@aq @a
A recursive macro calls itself at the end of its recording, causing it to repeat indefinitely until a command inside it fails (like a search hitting the end of
:let @q = substitute(@q, 'old', 'new', 'g')
When a recorded macro has a typo or needs a small tweak, re-recording the entire thing is error-prone.
:let @/ = @a
Vim's search register (@/) holds the current search pattern — the same one used by n, N, *, and hlsearch highlighting.