How do I use a Vim expression to dynamically compute the replacement in a substitution?
:s/\d\+/\=submatch(0)+1/g
The \= prefix in a :substitute replacement field tells Vim to evaluate the following as a Vimscript expression rather than treating it as a literal string.
category:
registers
tags:
#search
#editing
#ex-commands
#registers
How do I inspect what key sequences are stored in a macro register?
When a macro behaves unexpectedly, :echo strtrans(@q) reveals exactly what is stored in register q—including invisible control characters—as human-readable
category:
macros
tags:
#macros
#registers
#debugging
How do I capture shell command output directly into a Vim register?
You can populate any Vim register with the output of an external shell command using :let @{register} = system('{command}').
category:
registers
tags:
#registers
#ex-commands
#shell
How do I define or modify a macro directly as a string without recording it?
Macros in Vim are stored in registers as plain text.
category:
macros
tags:
#macros
#registers
#ex-commands
#normal-mode
How do I insert the current filename into the buffer or use it in commands?
Vim has several read-only registers that hold special values.
category:
registers
tags:
#registers
#insert-mode
#normal-mode
#editing
How do I insert the full WORD under the cursor (including slashes and dots) into the command line?
When you are in command-line mode, inserts the word under the cursor (alphanumeric and _ only).
category:
command-line
tags:
#command-line
#editing
#registers
How do I programmatically combine or modify the contents of Vim registers?
You can manipulate register contents directly using the :let command with the @{reg} syntax.
category:
registers
tags:
#registers
#editing
#normal-mode
#ex-commands
How do I programmatically set the contents of a register from the command line?
The :let @{reg} = expr command lets you assign any string or expression directly into a named register without entering insert mode or performing a yank.
category:
registers
tags:
#registers
#ex-commands
#macros
#normal-mode
How do I create a macro that runs continuously until it hits an error?
A recursive macro is a macro that calls itself as its last step, causing it to loop automatically until an operation fails (such as reaching the end of the file
category:
macros
tags:
#macros
#registers
#normal-mode
#editing
How do I highlight a pattern in Vim without jumping the cursor to the next match?
Writing to the @/ register via :let @/ = 'pattern' sets Vim's last-search pattern directly — without performing a search or moving the cursor.
category:
registers
tags:
#registers
#search
#normal-mode
#ex-commands
How do I run a macro a specific number of times at once?
Prefix any macro execution with a count to repeat it that many times in a single command.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I edit a recorded macro without re-recording it from scratch?
When a recorded macro has a typo or needs a small tweak, you don't have to re-record it entirely.
category:
macros
tags:
#macros
#registers
#editing
#command-line
How do I access and manipulate the last search pattern as a register?
Vim stores the last search pattern in the special / register.
category:
registers
tags:
#registers
#search
#command-line
How do I re-insert the text I typed in the previous insert session?
While in insert mode, pressing re-inserts the exact text you typed during your previous insert session.
category:
editing
tags:
#insert-mode
#editing
#registers
How do I recover the last small deletion without disrupting my numbered registers?
Vim silently stores every deletion of less than one line in the special "- register (the "small delete" register).
category:
registers
tags:
#registers
#editing
#normal-mode
How do I define or modify a macro without recording keystrokes?
Instead of recording a macro with q, you can assign any string directly to a named register using :let @{register} = 'keys'.
category:
macros
tags:
#macros
#registers
#ex-commands
#normal-mode
How do I run a substitute command without overwriting my last search pattern?
:keeppatterns %s/old/new/g
The :keeppatterns modifier runs any Ex command without modifying Vim's last search pattern (stored in @/).
category:
command-line
tags:
#search
#ex-commands
#command-line
#substitute
#registers
How do I run text I've yanked or typed as a Vim macro without recording it first?
Vim macros are stored in registers — and you can execute any register as a macro with @{register}.
category:
macros
tags:
#macros
#registers
#editing
#normal-mode
How do I copy lines to a different location in the file without overwriting my yank register?
The :t command (short for :copy) copies addressed lines to a destination line number, leaving the unnamed register untouched.
category:
command-line
tags:
#ex-commands
#editing
#normal-mode
#registers
How do I paste text that automatically matches the indentation of the current line?
When you copy code from one indentation level and paste it at another, p preserves the original indentation, leaving your code misaligned.
category:
editing
tags:
#editing
#indentation
#registers
#normal-mode