How do I browse and restore previously deleted text using Vim's numbered registers?
"1p then u. to cycle through delete history
Vim silently maintains a rolling history of your last 9 deletions in numbered registers "1 through "9.
"1p then u. to cycle through delete history
Vim silently maintains a rolling history of your last 9 deletions in numbered registers "1 through "9.
<C-r><C-r>{register}
In insert mode, {register} pastes the register's contents but runs it through Vim's insert-mode processing — including autoindent, textwidth wrapping, and for
: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.
:let @a = system('cmd')
You can populate any Vim register with the output of an external shell command using :let @{register} = system('{command}').
"%p
Vim has several read-only registers that hold special values.
:let @a = @a . @b
You can manipulate register contents directly using the :let command with the @{reg} syntax.
:let @a = "value"
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.
:let @/ = 'pattern'
Writing to the @/ register via :let @/ = 'pattern' sets Vim's last-search pattern directly — without performing a search or moving the cursor.
"/
Vim stores the last search pattern in the special / register.
"-
Vim silently stores every deletion of less than one line in the special "- register (the "small delete" register).
:call setreg('"', @", 'l')
Vim registers carry not just their text content but also a type: charwise (c), linewise (l), or blockwise (b).
"=
The expression register ("=) lets you evaluate any Vim expression and insert its result as text.
<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 @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
<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.
:<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.
"+q{keys}q
You can record macros into any register, including the system clipboard (+).
:echo @/
The / register holds the most recent search pattern.