2018-03-10 A tip on yanking

I have a few longer posts in the works, but for today I want to share a simple trick. We Emacs users all know and love the kill ring, and many of us know about M-y (yank-pop) and even C-u ... C-y (i.e., a numeric argment to yank). For those who don’t know: C-u 1 C-y is equivalent to plain C-y, but C-u 2 C-y (or just C-2 C-y) inserts the previous killed text (much like C-y M-y), and also marks it as the current one. With higher arguments, it inserts earlier kills.

However, you can also give non-positive arguments to C-y. For instance, C-0 C-y yanks the oldest kill (assuming you haven’t yet made your kill ring overflow, which depends on the kill-ring-max variable, defaulting to 60, and that you haven’t messed up the kill ring with M-y or prefix arguments to C-y.) Also, C-- C-y inserts the second earliest kill in history (under the same assumptions).

I don’t know how useful it is – you can always say C-y M-- M-y for that, too – but if you need it, it’s there. (One use-case would be when you yanked something from back in the history and then want to get back to something killed later.) Also, if you find yourself inserting various texts repeatedly, you might want to check out registers, which can hold arbitrary texts or even other useful things. And if you need to insert texts with variable elements (or cannot memorize one-letter register names), Yasnippet might be for you.

CategoryEnglish, CategoryBlog, CategoryEmacs