Learn Vim at your own pace with my self-study Core Vim Course.

Learn more

Learn Vim at your own pace with my self-study Core Vim Course.

Meet the yank register

#52

Run time:

Vim’s default register is not a safe place to keep yanked text that you want to paste later. It’s all too easy to clobber the default register with a d or x command. Luckily, the last yanked text is kept safe in Vim’s yank register.

Shownotes

From Vim’s documentation (:help quote0):

Numbered register 0 contains the text from the most recent yank command, unless the command specified another register with [“x].

I call "numbered register 0” the yank register. You can paste from the yank register with the command: "0p. That comes in really handy when the text you want to paste is no longer present in the default register.

A note on Vim’s jargon

Vim uses the terms delete, yank, and put, in place of the more standard terminology cut, copy, and paste. Starting with the same letter, put and paste are easily interchangable. Once you get used to the word yank, it becomes synonymous with copy. But Vim’s use of the word ‘delete’ is problematic.

In most contexts, the word delete just means remove. But Vim’s delete operation copies the text into a register, then removes it from the document. In other words, Vim’s delete operation behaves like a cut.

That raises a question: if Vim’s delete command is really a cut operation, does Vim have anything equivalent to a true deletion? The answer is slightly oddball: writing to the ‘blackhole register’ performs a true deletion.

Standard terminology Vim’s jargon
paste put
copy yank
cut delete
delete delete and write to “blackhole” register

Nothing returns from the blackhole register. It’s the Vim register equivalent of /dev/null. To perform a true deletion in Vim, prefix the delete command with "_ for example: "_diw would delete the current word without saving a copy in a register.

I find Vim’s terminology to be unhelpful, so I try to make a point of describing the d{motion} command as “cut the specified text” (rather than delete). Likewise for x, c, s, and so on.

Further reading

Comments

Level-up your Vim

Training

Boost your productivity with a Vim training class. Join a public class, or book a private session for your team.

Drew hosted a private Vim session for the shopify team that was one of the best workshops I have ever attended.

John Duff, Director of Engineering at Shopify

Publications

Make yourself a faster and more efficient developer with the help of these publications, including Practical Vim (Pragmatic Bookshelf 2012), which has over 50 five-star reviews on Amazon.

After reading it, I've switched to vim as my default editor on a daily basis with no regrets. ★★★★★

Javier Collado

Learn to use Vim efficiently in your Ruby projects

In association with thoughtbot, one of the most well respected Rails consultancies in the world, I've produced a series of screencasts on how to make navigating your Ruby projects with Vim ultra-efficient. Along the way, you’ll also learn how to make Ruby blocks a first-class text object in Vim. This lets you edit Ruby code at a higher level of abstraction. Available to buy from thoughtbot..