The Selection Registers


We mentioned previously that each time text is yanked or deleted it is copied to the unnamed register. When more text is yanked or deleted, the previous unnamed register content is lost. In many cases it would be convenient to retain previously-yanked (or deleted) content, and the numbered registers are intended to help.

When text is written to the unnamed register it is also written to register 0, which is the first numbered register. The next time text is yanked or deleted, the content in register 0 is shifted to register 1, then copied into register 0. This process repeats, so that text is retained for up to 9 yanks and/or deletes. When text reaches register 9, it will finally be lost upon the next yank or delete.

In principal this is very useful behavior, but there are a few conditions that make using the numbered registers a bit less useful than it could be. Yanked or deleted text is only passed to the numbered registers if:

  1. it was not directed to a named register or the black-hole register, and

  2. the text is longer than one line

These conditions make the numbered registers a bit less predictable than they could be, which sometimes leads to surprising results. However, they can often be used in tandem with the :registers command to manually recover yanked text that had been accidentally over-written.