Vim Registers

If you haven’t done so already, I’d recommend reading the section on “buffers” first. Registers are very similar to buffers they’re just accessed a bit differently.

The Yank & Delete Registers

(The rolling clipboard)

Unnamed Registers

When you delete lines of text you are also pushing them onto a stack of 9 numbered registers. Think of it as a rolling clipboard containing the last 9 items.

You can put any of the last 9 yanks or deletions into the current text by saying "<num>p where <num> is the number of the register you want to paste. E.g. "1p to paste the last thing you deleted (equivalent to p) and "2p for the one before that. This is, of course, pretty much useless for normal humans who don’t memorize the order they deleted things and then number those memories.

Named Registers

Fortunately there is useful, and memorable way to work with multiple named registers. Vim lets you name your registers whatever you want… as long as the name is one of the 26 letters in the English alphabet. ;) To yank or delete into a named register you precede your y or d command with a double quote ("). Yes, " is the comment character in VimScript, and yes that’s very odd.

If you wanted to yank the current line into register c you would say "cy. Unfortunately, the position of the number is reversed compared to normal yanking. Normally, to yank the current line and the next 2 you’d say y2 but to yank the current line, and the next 2 after it into the c register you would say "c2y

Listing Registers

Listing registers is pretty simple. Just type :registers. You can also filter it to just the ones you want. If you had been using a through c as named registers you could say :register a b c and it would just show you those.

Getting Stuff Out of Registers

As mentioned above, you put it. If you wanted to put the thing in register 9 you’d "9p. If you wanted to put the thing in register z you’d "zp. Note that I’m not prefacing those with :. You have to type this blind.

Stuff you’ll probably never need to know

(but will explain some of the items you see when you run :registers)

There are ten types of registers:

  1. The unnamed register “”
  2. 10 numbered registers “0 to “9
  3. The small delete register “-
  4. 26 named registers “a to “z or “A to “Z
  5. three read-only registers “:, “., “%
  6. alternate buffer register “#
  7. the expression register “=
  8. The selection and drop registers “*, “+ and “~
  9. The black hole register “_
  10. Last search pattern register “/

See :help registers for more details.