Step 7 of 7

6. Copying And Pasting

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 shift the 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!

Work through the checklist below. Once you’ve deleted the lines, it’s worth examining the number registers with the :reg command — you should see that the lines you deleted first have shifted into the higher number registers.

  1. Delete the five lines, in order Each new deletion shifts the older ones down the number registers — put the cursor on This is line number 1. and press dd five times.
  2. Recover the oldest deletion The first line you deleted has shifted into the "5 register — move to the bottom of the file and type "5p.
Delete the five lines, in order Each new deletion shifts the older ones down the number registers — put the cursor on This is line number 1. and press dd five times.

Next: Recover the oldest deletion

Loading editor…