← All lessons

6. Copying And Pasting

Step 6 of 7

The zero register

Vim also has registers for the numbers, 0 through 9. These are managed by Vim, and are filled with text from the yank and delete commands.

In this section, we’re going to focus on the "0 register. This register is particularly special because it always contains the text from the most recent yank command (unless that yank command used a specific register).

This is useful because, if you recall, the default register is populated with the contents of deletions and changes too. As a consequence, it’s very easy to accidentally overwrite the text in the default register by accident.

In practice, this means that you can use "0p to put the last text you yanked, no matter how many deletions and changes happened afterwards. "0 is only ever written to when you yank, so you don’t have to worry about deletes and changes overwriting its contents.

Try this in the editor. Yank the first line, and then delete the subsequent lines with dd. Then, try putting from the "0 register with "0p. The output should be line that you initially copied.

Loading editor…