2009-01-09

the kill-ring

Last time, I discussed registers, and mentioned the kill-ring. The kill-ring is the 'normal' clipboard emacs uses for cut/copy/paste of text. The cool name comes from the fact that in emacs terminology, 'killing' means what 'cutting' means in many other programs. The kill-ring contains the cut (and copied!) text parts; cut-copy-paste have their own entry.

As mentioned in the registers entry, many programs only allow you to paste the last copied/cut text block, and that is what the kill-ring does by default (when you press C-y). However, you can choose older ones using the menu (Edit/Paste from kill menu). Alternatively, you can use a prefix key (e.g., M-3 C-y will insert the third most recently killed ('cut') text).

The kill 'ring' behaves mostly like a list; by default (emacs 22, 23) there are 60 positions available in the ring, after which older entries are thrown away. You can put (setq kill-ring-max 120) in your .emacs in the unlikely case that 60 is not enough.

Update:An anonymous commenter mentions the useful M-y ('yank-pop') key binding, which lets you cycle through the items in the kill-ring. Quite useful indeed, thanks!

If you're using the GTK+-version of emacs (the graphical version in X/Linux/Unix environments), you can even have the Edit/Paste from kill menu-menu in a separate frame (window), and paste text by clicking there. To this, go to the menu Edit/Paste from kill menu, and click on the dotted line at the top of the sub menu.

6 comments:

Anonymous said...

Also, after yanking with C-y, you can cycle through previous items in the kill ring with M-y.

Anonymous said...

I find it humorous that the most useful command when using the kill ring is in the comments of the article.

I have known that I should read up on the kill ring for some tine because it would be useful for me to know the commands. Thanks for the great article.

djcb said...

@Anonymous(1): ah - that's a nice addition. I updated the blog entry, thanks!

Anonymous said...

You might want to update it right, too :)

It's M-y, not C-y.

djcb said...

@anonymous: *#$#(*^@#*)! ok, fixed, thanks.

hrbg said...

Other useful command is M-x kill-ring-search

Which allows you to search your previous killings