← All lessons

6. Copying And Pasting

Step 7 of 7

The number registers

We now know that "0 stores the contents of the last yank. So, what about registers 1 through 9?

Vim uses these registers to store the contents of the last deletions. This is incredibly useful for recovering previously deleted text.

"1 contains the text deleted by the most recent delete or change command (unless the command specified another register or the text is less than one line). With each subsequent deletion or change, Vim will shifts contents of "1 into "2, "2 into "3, and so on. The contents of "9 are then lost.

In practice, this means the text from your recent deletions are stored across the number registers, with the most recent deletion being stored in "1 and the oldest deletion being stored in "9. So even text that you deleted from a while ago isn’t fully gone!

Try this in the editor. Delete the lines, and then examine the contents of the numbered registers with the :reg command. You should see that the lines you deleted first are in the higher number registers.

Of course, you can recover and of the deleted lines by using, for example, "3p.

Loading editor…