This page looks best with JavaScript enabled

Vim Registers

 ·  ☕ 3 min read  ·  🥓🥓🥓 werkn

What are Vim Registers

I like to think of Vim registers as predefined variables you can yank, delete and paste bits of text to and from. Think of it like a clipboard power-up that you never new you wanted. When you want to you can yank to any of the following registers a-zA-Z0-9.%#:-.

Note: 0-9.%#:- are special registers that will be explained shortly. For now stick to a-zA-Z to avoid any problems.

Tip: Don’t forget Vim help, try running :h " for an overview of registers.

Basic Syntax

From normal mode you copy to a register using "{a-zA-Z}y{motion}. Where {motion} is your typical motions you provide while yanking, ie: y$ to yank from the cursor to the end of the line, or yy for the entire line.

Tip: If you use the capital variation A-Z you will append to the existing lower case register. This is useful for copying multiple bits of text to the same register.

From normal mode to paste from a register you enter "{a-zA-Z}{count}p. Count refers to the number of times to paste the buffer.

Tip: Capital variations behave the same as when pasting regularly, ie: p paste after cursor, whereas P paste before.

Copy the following text into Vim and try to yank, append and paste text yourself.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Example:  Yank to register with appending
# "ay$
abcdefgh

# "Ay$
ijklmnop

# "Ay$
qrstuvwxyz

# "ap
expect: abcdefghijklmnopqrstuvwxyz

Small Delete and Numbered Registers

Vim uses numbered registers "{0-9}- for special purposes, this was a little confusing for me at first. So I’ve outlined their usage in the table below:

Register Description
"0 Contains text from the most recent yank
"1-9 Essentially a queue of the most recent deletions and changes. So "1 will contain the most recent delete or change, and "9 the oldest. Yank operations ARE NOT recorded in these registers
"- The small delete register stores text from commands that delete less than one line

Read-only Registers

The following read-only registers can only be used with p and P, meaning you can’t actaully assign to them manaully:

Register Description
". Contains last inserted text
"% Contains the name of the current file
": Contains the most recent executed command-line, ie: :reg.

Tip: I use ": a lot in combination with @: to repeat my previous command line. Try it now by enter :req<Enter> and then from normal mode running @:.

Unnamed Register

Whenever you perform a delete, yank, etc… the default register this content is stored to is the "", or unnamed register.

Whenever you put, p or P you are using whatever is stored in the unnamed register, essentially running ""p behind the scenes.

Knowing Whats in Your Registers

You can see the current state of our registers by running :reg. This will display something like the following:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
:reg
--- Registers ---
""   set bell-style none
"0
"1   set bell-style none
"2
"3
"4   set bell-style none
"5
"6     url = "gallery/photo"
"7     name = "Photo"
"8     parent = "gallery"
"9   [[main]]
"-
".
":   q

References:

Share on

Ryan Radford
WRITTEN BY
werkn
Developer / IT Guy / Tinkerer