How do I read from and write to files directly in Vimscript without shelling out to external commands?
readfile() and writefile()
readfile({path}) reads a file and returns its contents as a list of lines, and writefile({list}, {path}) writes a list of lines back to disk.
category:
config
tags:
#vimscript
#ex-commands
#config
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 add custom markers or icons in Vim's sign column next to specific lines without any plugins?
:sign define and :sign place
Vim's built-in sign system lets you define custom symbols and place them in the sign column — the narrow gutter to the left of line numbers.
category:
command-line
tags:
#command-line
#ex-commands
#vimscript
How do I save and restore the current window layout after temporarily changing window sizes in a Vim script?
The winrestcmd() function returns a string of Ex commands that, when executed, restore all window sizes to their state at the time of the call.
category:
config
tags:
#config
#vimscript
#windows
How do I write vimrc configuration that works in both Vim and Neovim by detecting which one is running?
The has() function tests whether a feature or capability is available, returning 1 (true) or 0 (false).
category:
config
tags:
#config
#vimscript
#compatibility
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 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 register an autocommand that automatically removes itself after firing once?
The ++once flag, added in Vim 8.
category:
config
tags:
#config
#autocmd
#events
#vimscript
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 execute a motion or command without adding an entry to the jump list?
The :keepjumps modifier lets you run any movement or command without recording a new entry in the jump list.
category:
navigation
tags:
#navigation
#ex-commands
#jump-list
#normal-mode
#vimscript
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 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
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 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 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 evaluate a Vimscript expression and use the result as my command-line input?
Pressing e on the command line opens a special prompt that lets you type a Vimscript expression.
category:
command-line
tags:
#command-line
#ex-commands
#vimscript
#insert-mode
How do I programmatically set a register's content in Vim without yanking?
Vim's :let command lets you assign a value directly to any named register without performing a yank or delete operation.
category:
registers
tags:
#registers
#macros
#vimscript
#ex-commands
#normal-mode