12

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 4

9

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.
1
  • oh my, I'm one minute late!
    – JeanPierre
    Commented Nov 3, 2016 at 13:48
7

You have a few options for this :-

  1. You can use counsel which provides with the command counsel-yank-pop which will show the list of all the yanked text and you can select anyone of them using ivy (this is what I use). In your case, you can press M-> to go the first entry in the kill-ring.

  2. if you use helm, there is the command helm-show-kill-ring which does the same as mentioned above, except uses helm narrowing framework instead of ivy.

  3. 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 :)

3

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.

1

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:

  • browse-kill-ring+.el:

    • You can browse (or pop) other rings, in addition to the kill-ring — in particular, the secondary-selection-ring (see secondary-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 the secondary-selection-ring of second-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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.