Registers in Vim
TABLE OF CONTENT
- Registers in Vim are simply different locations where Vim could store texts.
- a register can be accessed by using
"as prefix. For example: key
"rcan access register
What content a register is currently holding, can be revealed by using command
:reg <name of register>. Without the name,
reg command would list all
registers filled with certain data.
- yank to register
- delete to register
- put from register
Types of Registers
There are ten types of register vim comes with. Here are some of the most important ones.
- unnamed register
- named register
- numbered registers
- blackhole register (
- read-only registers
- expression register(
- search register
vim have a default registers, which is used if the commands are not prefixed
with a register name. This register is known by the name unnamed register.
This register can be accessed with
"". This register would always contain the
latest yanked/deleted texts.
There are 26 named registers. By default, they are not being used by Vim.
To use, say
a register, one should prepend command with
"a. For example:
"adw (delete a word and store in
There are two ways to use named register. If one uses small caps alphabet, the content which was previously stored in it, would be overriden. In case of capital letter, the content would be appended.
Denoted by numbers 0 to 9. These registers stores previously yanked and deleted content. Register 0 would store the latest yank. And register 1 to 9 would store the last 9 deleted texts(even after shutdown and reboot). 1 being the latest and 9 the oldest delete.
One does not loose yanked/deleted texts in vim. They just don’t know where to look for it!
Black Hole Register is a register which does not stores anything. Whatever
is directed to this register, would get vanished. This register is denoted by
"_d would completely delete a word. obviously, can be brought back
As the name suggests, they can’t be used by user for the purpose of storing arbitary texts. There are 4 read-only registers:
".: Stores the last inserted texts.
"%: Stores the current(relative) file path
":: Stores most recently executed command. Goes quite handy with @(command runner. example, @:)
"#: stores the (relative) location of alternate file for current window.
This register stores the value of an expression. When
<C-r>= is pressed in
insert mode, a
= sign would show up in command line. Any expression run in
command line would be stored in expression register (
<C-r>=system('ls') would write down the result of
cursor-line, and store the command in
Stores the latest search term searched with
#. Useful when one
needs to re-type a complex term or RegEx. Can be accessed using