Emacs has this very handy kill-ring that can be cycled through after yanking, by pressing M-y
repeatedly. Is there a way to switch the cycling direction? So I don not need to cycle through all when I actually want to get to the very first one?
4 Answers
This is from 12.2.2 Yanking Earlier Kills:
‘M-y’ can take a numeric argument, which tells it how many entries to advance the “last yank” pointer by. A negative argument moves the pointer toward the front of the ring; from the front of the ring, it moves “around” to the last entry and continues forward from there.
You have a few options for this :-
You can use
counsel
which provides with the commandcounsel-yank-pop
which will show the list of all the yanked text and you can select anyone of them usingivy
(this is what I use). In your case, you can pressM->
to go the first entry in thekill-ring
.if you use
helm
, there is the commandhelm-show-kill-ring
which does the same as mentioned above, except useshelm
narrowing framework instead ofivy
.If you don't want either of the above options, then have a look at the package
browse-kill-ring
.
Also, a useful variable kill-do-not-save-duplicates
will do as the name suggests :)
It seems you could use -1 as a prefix argument to M-y
as hinted by the manual:
M-y can take a numeric argument, which tells it how many entries to advance the last-yank pointer by. A negative argument moves the pointer toward the front of the ring; from the front of the ring, it moves around to the last entry and continues forward from there.
Check out Emacs Wiki page Browse Kill Ring. The basic feature is to show you a buffer of all kill-ring entries and let you act on them (edit, yank, etc.).
Alternatives to, and enhancements of, the basic feature are also presented on that page, including these:
-
You can browse (or pop) other rings, in addition to the
kill-ring
— in particular, thesecondary-selection-ring
(seesecondary-sel.el
).You can copy or move selections from one ring to another (using
c
).Lets
delete-selection-mode
replace the active region whenever you insert a kill.
Icicles lets you clean up the kill ring selectively during completion, deleting entries on the fly. You can sort completions in various ways.
C-- C-y
yanks from the kill ring using completion.M-y
at top level (i.e., not after a yank from either the kill ring or thesecondary-selection-ring
ofsecond-sel.el
) yanks from one of those rings using completion. It yanks a kill by default, but a secondary selection if you use a prefix argument.
When you use either of these, you can cycle among completion candidates (the entries in the ring), in various orders, or you can choose any of them directly, without cycling.