How do I run a shell command from Vimscript and capture its output as a list of individual lines?
systemlist({cmd}) runs a shell command and returns the output as a list of strings, one per line — unlike system() which returns everything as a single string
category:
command-line
tags:
#vimscript
#ex-commands
#registers
#macros
How do I define or edit a macro's content programmatically without re-recording it?
You can assign a string directly to any register using :let, turning it into a macro instantly.
category:
macros
tags:
#macros
#registers
#vimscript
#normal-mode
How do I run a macro on every line in the file silently, ignoring errors on lines where the macro fails?
Combining :silent!, the % range, and :normal @q gives you a powerful pattern for applying a macro across an entire file while gracefully skipping lines that don
category:
macros
tags:
#macros
#editing
#ex-commands
#normal-mode
How do I use a count prefix in a custom Vim mapping where no count defaults to 1?
The v:count1 variable holds the count typed before a command, defaulting to 1 if no count was given.
category:
macros
tags:
#macros
#vimscript
#mappings
#normal-mode
How do I define key mappings in Neovim using Lua instead of the old Vimscript API?
vim.
category:
config
tags:
#config
#macros
#normal-mode
How do I create a Vim mapping where the keys it produces are computed dynamically at runtime?
:nnoremap <expr> {key} {expression}
The argument to any map command (:nmap, :inoremap, etc.
category:
config
tags:
#config
#macros
#insert-mode
#normal-mode
#ex-commands
How do I run a macro on every line in a specific line number range?
The :normal command lets you execute Normal mode keystrokes over a range of lines.
category:
macros
tags:
#macros
#normal
#range
#ex-commands
How do I append text to a named register programmatically without re-recording a macro?
Vim registers are just strings, and you can read and write them directly using the :let command.
category:
registers
tags:
#registers
#vimscript
#macros
#editing
How do I detect which register was specified before executing a custom mapping in Vim?
When writing custom mappings or operator functions, v:register gives you the register name that the user prefixed the mapping with.
category:
registers
tags:
#registers
#macros
#normal-mode
#ex-commands
How do I extract regex capture groups from a string in Vimscript?
matchlist({str}, {pattern}) runs a regex match and returns a list of all captured groups, making it the idiomatic way to extract structured data from strings in
category:
macros
tags:
#vimscript
#macros
#ex-commands
#search
How do I read a single keystroke from the user inside a Vimscript mapping or function?
getchar() blocks and waits for the user to press a key, returning its numeric character code.
category:
macros
tags:
#macros
#vimscript
#normal-mode
#registers
How do I suppress the 'Pattern not found' error when a substitution has no match?
The e flag in Vim's :substitute command silently ignores the "E486: Pattern not found" error when the pattern does not match anything.
category:
search
tags:
#search
#substitute
#ex-commands
#macros
#editing
How do I edit a macro in-place using Vimscript without re-recording it?
: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.
category:
macros
tags:
#macros
#registers
#vimscript
#editing
How do I create a mapping that applies only in visual mode but not in select mode?
:vmap applies to both visual mode and select mode, which can silently break snippet plugins (like UltiSnips, LuaSnip) that use select mode to position the curso
category:
config
tags:
#visual-mode
#normal-mode
#macros
How do I make Vim show error messages that are silently swallowed inside :silent! or :try blocks?
When troubleshooting mappings or scripts that use :silent!, errors disappear without a trace.
category:
config
tags:
#config
#macros
#ex-commands
How do I edit an existing macro without re-recording it from scratch?
When a recorded macro contains a typo or needs a small tweak, you can modify it directly via the :let command rather than re-recording the entire sequence.
category:
macros
tags:
#macros
#registers
#editing
#normal-mode
How do I run a Lua expression on every line of a buffer in Neovim?
Neovim's :luado command runs a Lua expression on each line of a range, allowing you to transform text using the full power of Lua's string library.
category:
command-line
tags:
#editing
#ex-commands
#macros
#normal-mode
How do I run normal mode commands in a script without triggering user-defined key mappings?
When you use :normal {cmd} in a Vimscript function, macro, or Ex command, Vim expands any keys through the user's current mappings first.
category:
macros
tags:
#macros
#ex-commands
#normal-mode
#config
How do I edit or modify an existing Vim macro programmatically without re-recording it?
:let @q = substitute(@q, "old", "new", "g")
Vim macros are stored as plain text in registers, which means you can inspect and modify them like any other string.
category:
macros
tags:
#macros
#registers
#vimscript
#advanced
#editing
How do I capture Vim command output to a variable or register using the execute() function?
:let @a = execute('messages')
The execute() function (added in Vim 8.
category:
command-line
tags:
#ex-commands
#registers
#macros
#command-line