← All lessons

6. Copying And Pasting

Step 4 of 7

The unnamed register

When you yank with Vim, it doesn’t copy the text to your system’s clipboard (by default). Instead, it copies the text into a register. A register is just a storage location for text — like your system clipboard, but living within Vim. Vim has many registers, and each one has a unique identifier that we use to reference it.

Let’s not think about the different registers just yet, though. Most of the time, when we’re yanking/putting in Vim, we don’t even specify a register. In this situation, Vim will use the unnamed register, which you can think of as the default.

Something that’s particularly noteworthy is that the unnamed register gets modified when we’re doing deletions and changes (with d, c, x, etc) — not just when we’re yanking!

What does this mean? Deleting some text is the same as yanking it, and then deleting it. This is unintuitive at first, because it means that the text you just yanked can be overwritten by a delete. But it’s actually really useful; most of the time, you’re not deleting something, you just want to move it somewhere else.

Give it a try in the editor. Delete the first paragraph with dap, then navigate to the bottom of the file and put it with p. This feature is super useful for rearranging paragraphs, sentences, and code blocks.

Loading editor…