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 paste text before the cursor while leaving the cursor positioned after the pasted content?
The gP command works like P (paste before the cursor) but leaves your cursor after the pasted text rather than at its beginning.
category:
editing
tags:
#editing
#paste
#registers
#normal-mode
How do I highlight all occurrences of a yanked word without typing a search pattern?
After yanking text, you can promote it directly to the search register with :let @/ = @".
category:
registers
tags:
#registers
#search
#hlsearch
#normal-mode
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 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 rearrange or transform captured groups in a substitution using Vimscript?
:s/\(\w\+\) \(\w\+\)/\=submatch(2) . ' ' . submatch(1)/
The submatch(N) function lets you access individual capture groups inside a \= (expression replacement) in a substitution.
category:
search
tags:
#search
#editing
#ex-commands
#registers
How do I cycle through the numbered delete registers using the dot command?
When you paste from a numbered register with "1p, Vim's dot command (.
category:
registers
tags:
#registers
#editing
#normal-mode
#undo-redo
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 read the contents of a Vim register into a variable or expression using Vimscript?
The getreg({name}) function returns the content of any register as a string.
category:
registers
tags:
#registers
#ex-commands
How do I briefly highlight text after yanking it to get visual confirmation of what was copied?
The TextYankPost event fires immediately after any yank operation completes — including y, Y, dd, dw, and any other command that writes to a register.
category:
config
tags:
#config
#autocommands
#registers
#visual-mode
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 paste the contents of a register literally in command-line mode without interpreting special characters?
In command-line mode, {reg} inserts a register's contents — but it processes certain sequences, potentially misinterpreting backslashes, pipe characters, or e
category:
registers
tags:
#registers
#command-line
#search
#editing
How do I paste register contents at the beginning of a file without moving the cursor there first?
The :put Ex command inserts register contents as a new line below the specified line number.
category:
editing
tags:
#editing
#ex-commands
#registers
#normal-mode
How do I evaluate a Vimscript expression and insert the result into a command-line command?
<C-r>= (command-line mode)
Just like = lets you insert evaluated expressions in insert mode, you can use it inside an Ex command on the command line to embed any Vimscript expression resu
category:
command-line
tags:
#registers
#ex-commands
#command-line
How do I paste a register literally in insert mode without triggering auto-indent or special key handling?
When you press x in insert mode to paste a register, Vim inserts the text "as if you typed it" — meaning autoindent, textwidth, and other insert behaviors can
category:
registers
tags:
#registers
#insert-mode
#editing
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 get the current search match index and total count programmatically in Vim?
The searchcount() function returns a dictionary containing the current search state: which match the cursor is on, how many total matches exist, and whether the
category:
search
tags:
#search
#ex-commands
#registers
#completion
How do I paste the name of the alternate (previously edited) file into the buffer?
The # register holds the name of the alternate file — the file you were editing just before the current one.
category:
registers
tags:
#registers
#buffers
#navigation
#normal-mode