Setting Registers

Previous section discussed the unnamed register, which Vim automatically sets when text is yanked or deleted. In this section we introduce the named registers, which allow unique text to be stored in memory then retrieved by specifying the name of the register that contains the desired text.

Registers are named using ASCII letters, allowing up to 26 different pieces of text to be stored at a time. To access a value stored in a register, use a double quote followed by the register name:

"{name}y

So, to yank text an store it in the a register, select some text, then type "ay. When the name is not provided, Vim defaults to the unnamed register, as we saw in the previous section.

Note:

To explicitly refer to the unnamed register, use the name ", for example ""y

To demonstrate, select some text in a buffer:

Select text to yank
2w
Beautiful·is·better·than·ugly.
Explicit·is·better·than·implicit.
Simple·is·better·than·complex.
Complex·is·better·than·complicated.
VISUAL
Top
1:14
 

Then yank the selected text to register a.

Yank text to register a
"ay
Beautiful·is·better·than·ugly.
Explicit·is·better·than·implicit.
Simple·is·better·than·complex.
Complex·is·better·than·complicated.
NORMAL
Top
1:1
 

Then review the current register contents using the :registers command

View the registers
Beautiful·is·better·than·ugly.
Explicit·is·better·than·implicit.
Simple·is·better·than·complex.
Complex·is·better·than·complicated.
NORMAL
Top
1:1
 
:reg
Type Name Content
  c  ""   Beautiful is b
  c  "a   Beautiful is b

which shows that the selected content is available in the a register. Additionally, since the most-recent yanked or deleted text is always put in the unnamed register, that register has also been populated with the selected text.

Lower-case vs Upper-case

Vim allows either lower-case or upper-case ASCII letters to be used when referencing the named registers, and either value references the same content. However, the way the content is used varies between them:

When using lower-case for the register name Vim replaces the content of the specified register with the new content. This is usually the desired behavior when yanking text, so in most cases the lower-case name should be used.

Upper-case letters behave slightly differently: when an upper-case letter is used to send text to a register, the text is appended to any existing content in the specified regarding.

When accessing the value stored in a register, upper-case and lower-case names behave the same.