How do I run a macro as many times as needed until it hits an error and stops automatically in Vim?
Vim macros stop executing the moment any step in the macro causes an error — a failed search, a motion that cannot proceed, or a substitution with no matches.
category:
macros
tags:
#macros
#editing
#normal-mode
How do I execute the contents of the system clipboard as a Vim macro?
In Vim, @{register} executes the contents of any register as a macro.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I add more keystrokes to the end of an existing macro without re-recording the whole thing?
qQ (or any uppercase register letter)
When recording a macro with qq, you can append additional keystrokes to the existing macro by recording into the uppercase version of the same register.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I create a mapping that runs an Ex command without switching modes or affecting the current state?
nnoremap <key> <Cmd>command<CR>
The special key (Vim 8.
category:
config
tags:
#config
#macros
#ex-commands
#normal-mode
#insert-mode
What is the difference between :norm and :norm! when running normal commands from the command line?
Both :norm and :norm! execute a sequence of Normal mode keystrokes from the command line or a script, but they differ in how they handle user-defined mappings.
category:
command-line
tags:
#ex-commands
#normal-mode
#macros
#vimscript
How do I edit the contents of a macro register using Vimscript without re-recording it?
:call setreg("a", substitute(getreg("a"), "old", "new", "g"))
The getreg() and setreg() functions let you read and write register contents as plain strings, making it possible to surgically edit a macro without re-recordin
category:
registers
tags:
#registers
#macros
#vimscript
#ex-commands
How do I programmatically inject keystrokes into Vim's input queue from a function or mapping?
The feedkeys({keys}, {flags}) function inserts a string of keystrokes into Vim's input queue as if the user had typed them.
category:
command-line
tags:
#ex-commands
#macros
#config
#normal-mode
How do I make a macro prompt for user input at a specific point during its execution?
<C-r>=input('Enter: ')<CR>
By embedding =input('prompt: ') inside a recorded macro, you can pause the macro at any point to ask for user input and insert the result.
category:
macros
tags:
#macros
#insert-mode
#registers
#editing
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.
category:
macros
tags:
#macros
#registers
#vimscript
How do I run a substitution in Vim without getting an error when the pattern is not found?
:%s/pattern/replacement/ge
The e flag on :substitute silences the "Pattern not found" error that Vim normally reports when a substitution has no matches.
category:
search
tags:
#search
#ex-commands
#substitution
#macros
How do I append more commands to an existing macro without re-recording it from scratch?
Recording a macro with an uppercase register letter appends to the existing macro in the corresponding lowercase register instead of overwriting it.
category:
macros
tags:
#macros
#registers
#recording
#normal-mode
How do I combine two recorded macros into one without re-recording them from scratch?
Macros in Vim are stored as plain text in named registers.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I trigger wildcard filename completion from inside a custom key mapping in Vim?
The wildchar option (default ) triggers wildcard completion interactively on the command line.
category:
config
tags:
#config
#macros
#command-line
#completion
How do I run a normal mode command from the ex command line without triggering my custom key mappings?
:normal {command} runs a sequence of Normal mode keystrokes from the command line (or a range of lines with :%normal), but it applies your custom key mappings.
category:
command-line
tags:
#ex-commands
#macros
#normal-mode
#command-line
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().
category:
macros
tags:
#macros
#registers
#normal-mode
How do I programmatically set a register's content or pre-load a macro using setreg()?
The setreg() VimScript function lets you populate any register with arbitrary content directly from the command line or a script — no recording required.
category:
registers
tags:
#registers
#macros
#vimscript
#normal-mode
How do I generate multiple lines of text using a Vimscript for loop from the command line?
:for i in range(1,5) | put ='item '.i | endfor
Vimscript's for loop is available directly from Vim's command line and can be used to generate repetitive or parameterized text without a macro or external scri
category:
command-line
tags:
#ex-commands
#macros
#editing
#normal-mode
How do I build a macro programmatically using Vimscript instead of recording it?
: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
category:
macros
tags:
#macros
#registers
#ex-commands
How do I create a macro that repeats itself automatically until it can no longer proceed?
A recursive macro ends by calling itself, so it loops automatically without you pressing @q repeatedly.
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I create a self-repeating macro that runs until there is nothing left to process?
@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).
category:
macros
tags:
#macros
#registers
#normal-mode
#editing