The kill-ring
is emacs' implementation of a copy-paste-clipboard. As
expected, it's more powerful than what most other editors offer - but at the
same time, it may be a bit hard to use. We already discussed the kill-ring
in the Emacs-Fu prehistory.
One of the more powerful features of the emacs kill-ring is that is allows for
multiple entries to be saved there. You can then retrieve those older
entries by using prefix arguments, that is: C-y
will retrieve the last
item from the kill-ring, while M-
n C-y
will retrieve the n th last
stretch of 'killed' (cut/copied) text. For example, M-2 C-y
will retrieve
the second last one.
Unfortunately, for most people it's quite hard to remember what was 'killed' and when and in what order… Those people can of course use the menu (Edit/Paste from kill menu), but that is not always so convenient, requires mousing around etc.
Edit: As Anynomous
mentions in the comments, one can of course use M-y
to
circle through the candidates. This is quite
useful, esp. when you have only a few items in the ring. Note, this command
only works just after a 'yank' (C-y
).
browse-kill-ring
Instead, using the handy browse-kill-ring
extension, you can open a buffer
which lists the contents of the kill ring, and you can move your cursor to the
desired item and insert it.
Installation in simple; first get the browse-kill-ring
package from EmacsWiki, or, alternatively, Debian/Ubuntu users can install the
emacs-goodies-el
-package.
Then, add to your .emacs
something like:
(when (require 'browse-kill-ring nil 'noerror) (browse-kill-ring-default-keybindings))
Now, the M-y
key binding will activate browse-kill-ring
iff the normal behavior (see above) is not available, i.e., when the last command was not a
'yank'. You can also edit the kill-ring (press C-h m
when in the
browse-kill-ring
-buffer to see the available bindings).
a little pop-up menu
While browsing EmacsWiki, I found another trick:
(global-set-key "\C-cy" '(lambda () (interactive) (popup-menu 'yank-menu)))
After which C-c y
will show a little pop-up menu with the your kill-menu
entries. It does not seem to fully synchronize with the (possibly edited)
entries you get from browse-kill-ring
, but it's a pretty neat way to
navigate through your kill-ring-buffers – if you don't have too many of them
(if so, you could customize the kill-ring-max
variable).