How do I insert the result of a Vim expression or calculation directly into text?
"=
The expression register ("=) lets you evaluate any Vim expression and insert its result as text.
"=
The expression register ("=) lets you evaluate any Vim expression and insert its result as text.
P (in visual mode)
When you paste over a visual selection using p (lowercase), Vim replaces the selection with your register contents — but the replaced text overwrites your unn
<C-r><C-r>{register}
In insert mode, {reg} pastes from a register but treats certain bytes as key inputs — so a register containing \n triggers a newline, \x08 triggers backspace,
:let @q = "dwelp"
Recording macros with q works well for simple sequences, but complex macros with special keys can be hard to get right in one take.
qQ...q
When you record a macro into register q with qq.
:let @a = substitute(@a, 'old', 'new', 'g')
After recording a macro or yanking text into a named register, you may need to tweak it — fix a typo in a recorded macro, change a variable name in yanked tex
gp
The standard p command pastes text after the cursor but leaves the cursor at the beginning of the pasted text.
<C-a> (in insert mode)
While in insert mode, pressing re-inserts whatever text you typed during your previous insert session.
<C-r><C-o>{reg}
When you use a in insert mode to paste register a, Vim inserts the text as if you typed it character by character.
:put a ... edit ... "ayy
Recorded macros are stored as plain text in registers, but editing them by re-recording is tedious for complex sequences.
qqqqqq{edits}@qq
A recursive macro calls itself at the end of its sequence, creating a loop that automatically repeats until a motion or command fails (such as hitting the last
qaq qa...@aq @a
A recursive macro calls itself at the end of its recording, causing it to repeat indefinitely until a command inside it fails (like a search hitting the end of
qaqqa{actions}@aq@a
A recursive macro is a macro that calls itself at the end of its recording.
:<C-r>"
When typing an Ex command or search pattern, you often need to insert text you've already yanked or deleted.
:let @+ = @"
Vim's :let @{reg} syntax lets you read from one register and write to another.
"1p then u then . to cycle
Vim stores your last 9 deletions in numbered registers "1 through "9.
"ayv
Using named registers with visual mode lets you store multiple independent snippets simultaneously.
"+q{keys}q
You can record macros into any register, including the system clipboard (+).
:echo @/
The / register holds the most recent search pattern.
"1pu.u.u.
Vim stores the last 9 deletions in numbered registers 1-9, with the most recent in register 1.