November 19, 2023
Vim registers are like cargo pants. You get to carry around multiple things and use them when you want, and your friends will think you are cool.
Have you ever wanted to paste something different later in a file or code? Vim registers allow you to do this.
There are different kinds of registers in Vim, and it can be a little confusing at first. Like anything else in Vim, take it one step at a time.
These words have the same meaning copy/yank and paste/put.
There are 10 types of registers in Vim for example read-only, black hole, expression, and others.
We only want to focus on the 2 common registers, numbered registers and named registers.
When you yank or delete something, the data automatically goes in the numbered registers, and they are numbered 1 through 9
Are only used when you put data in them, and they are labeled a through z
(These are the ones we want to use)
Chances are, you will only need to copy 2 or 3 things at a time. This makes it easier to learn. I suggest start with only using the named registers a, b, c.
View the registers
Use any of these commands:
:registers :reg :display :dis
Copy into registers
Define the register before you yank
Example: define register a with
"a and yank (copy) with
To copy something into one of the named (a through z) registers
highlight the data you want to copy and the command:
Copy to register a
Copy to register b
Paste from registers
When you are ready to paste, define the register
"b then put (paste)
Paste from register b
Practice with simple text copy and pasting in and out of registers a, b, and c. After you do it a couple of times it becomes easier.
You can always get more details with registers using help in Vim