How do I create a self-repeating recursive macro that runs until it reaches the end of the file?
A recursive macro calls itself at the end of its recording, causing it to repeat automatically until an error — such as reaching the end of the file — stops
category:
macros
tags:
#macros
#registers
#editing
How do I record a self-repeating recursive macro that automatically stops when it hits an error?
A recursive macro is one that calls itself at the end of its own recording.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I use a macro to automatically increment a number on each line?
By recording a one-step macro that increments a number and moves down a line, you can bulk-apply across as many lines as needed with a single count.
category:
macros
tags:
#macros
#editing
#normal-mode
How do I create a normal mode mapping that correctly captures and passes a count prefix to a function?
nnoremap <key> :<C-u>call MyFunc(v:count)<CR>
When writing custom mappings that call Vimscript functions, a common pitfall is that any count you type before the key (e.
category:
config
tags:
#config
#macros
#ex-commands
#normal-mode
How do I edit a macro without re-recording it?
:let @q = substitute(@q, 'old', 'new', '')
Vim macros are stored as plain text in named registers, which means you can inspect and modify them directly using :let and :echo.
category:
macros
tags:
#macros
#registers
#editing
#normal-mode
How do I repeat a macro as many times as possible until it fails?
Prefixing a macro invocation with a large count like 999@q tells Vim to run register q up to 999 times.
category:
macros
tags:
#macros
#normal-mode
How do I programmatically read and write Vim register contents including their type from Vimscript?
The setreg(reg, value, type) and getreg(reg, 1, 1) functions give you full programmatic control over registers, including their type (characterwise, linewise, o
category:
registers
tags:
#registers
#vimscript
#macros
#ex-commands
How do I register a Lua callback that fires before every keystroke to react to keyboard input?
vim.
category:
config
tags:
#ex-commands
#vimscript
#config
#macros
How do I make a key mapping fire immediately without waiting for longer mappings to time out?
nnoremap <nowait> {key} {action}
The flag on a mapping tells Vim not to delay waiting for a longer key sequence.
category:
config
tags:
#config
#normal-mode
#macros
How do I run a :normal command that ignores user-defined mappings?
:normal {cmds} executes normal-mode keystrokes from the command line, but it honors your custom key mappings — so remapped keys produce unexpected results in
category:
command-line
tags:
#ex-commands
#macros
#normal-mode
#command-line
How do I create a self-referential recursive macro that repeats until it fails?
A recursive macro in Vim calls itself at the end of its body, repeating automatically until one of its commands fails.
category:
macros
tags:
#macros
#registers
#advanced
#normal-mode
How do I check whether a register contains characterwise, linewise, or blockwise text?
The getregtype() function returns the motion type of a register's content — whether it was yanked characterwise, linewise, or as a visual block.
category:
registers
tags:
#registers
#ex-commands
#macros
How do I save my current window and return to it after navigating other windows from a script or function?
:let winid = win_getid() | ... | call win_gotoid(winid)
The wingetid() and wingotoid() functions let you bookmark a window by its stable integer ID and jump back to it reliably.
category:
buffers-windows
tags:
#buffers-windows
#ex-commands
#macros
How do I edit the contents of a macro using Vimscript string functions without re-recording it?
:let @q = substitute(@q, 'from', 'to', 'g')
Macros are stored as plain text in named registers, so you can manipulate them with any Vimscript string function.
category:
macros
tags:
#macros
#registers
#ex-commands
How do I pass special keys like Ctrl or arrow keys to :execute normal! in a Vimscript function or mapping?
:execute "normal! \<{key}>"
When building dynamic :execute normal! calls in Vimscript, you must use double-quoted strings with the \ notation so Vim interprets the special key codes.
category:
macros
tags:
#macros
#ex-commands
#normal-mode
How do I apply a recorded macro to a range of lines without re-recording it in Vim?
The :[range]normal @a command runs a recorded macro against every line in a given range.
category:
macros
tags:
#macros
#registers
#ex-commands
#normal-mode
#advanced
How do I run a normal mode command that bypasses all user-defined key mappings?
The :normal! command (abbreviated :norm!) executes a sequence of Normal mode keystrokes while completely ignoring user-defined mappings and abbreviations.
category:
command-line
tags:
#ex-commands
#normal-mode
#macros
#scripting
How do I run a Vim command and suppress all its output messages and error messages?
The :silent! modifier runs an Ex command without displaying any output or error messages.
category:
command-line
tags:
#command-line
#ex-commands
#macros
#config
How do I make Ctrl-A and Ctrl-X increment and decrement alphabetical characters in Vim?
By default, Vim's and commands only increment and decrement numbers (decimal, hex, binary).
category:
config
tags:
#config
#editing
#normal-mode
#macros
How do I apply a macro to every non-blank line in the file while skipping empty lines?
Combining the :global command with :normal lets you run a macro on every non-blank line in one shot.
category:
macros
tags:
#macros
#ex-commands
#global
#normal-mode
#editing