0

I often do something like this:

  1. Copy some stuff
  2. Go to where I need to paste it
  3. Paste it (C-y)
  4. Kill the rest of the line (C-k)
  5. Select what I just pasted, and copy it again
  6. Repeat steps 2-5

The whole "re-select what I just pasted" thing is not sensible, I know. On the other hand, I like the Emacs pasting behavior, so I don't want to enable all of what goes on with delete selection mode. There is also a whole collection of increasingly complicated routines you can write or borrow to rethink the kill-ring, but that too seems less about idioms and more about Emacs wrenching.

What is the most efficient (by keystroke count) way to accomplish this regular task, without building a complicated setup or changing to delete-selection-mode?

  • Instead of re-copying, yank (paste) twice (C-y then M-y) to skip to the second-to-last item in the kill ring. – Juancho May 26 '17 at 16:30
  • I would say that stackoverflow.com/a/5824302/319698 and stackoverflow.com/a/5823525/319698 are idioms, no elisp required. – npostavs May 26 '17 at 20:53
  • @npostavs Probably, but I wanted to get a canonical question into this site specifically. – bright-star May 26 '17 at 21:08
  • You should probably clarify if we're repeating just once, or n times. – npostavs May 26 '17 at 22:37
  • Sounds like you might just be able to do a search and replace. – db48x May 26 '17 at 23:00
2

[Posting this again here, but really think we ought to consider a policy of being able to close a question that duplicates one on StackOverflow.]


As it says here:

  1. If you want to repeatedly yank the same text, use the secondary selection instead of the region or killed text.

    What's missing from vanilla Emacs is a key binding to yank the secondary selection. I use C-M-y for that (see library second-sel.el).

  2. To get direct access to any kills in the kill ring, use M-y with Browse Kill Ring or with Icicles. In both cases, M-y at top level gives you access to all entries in the kill ring.

    And if you use library second-sel.el then, in addition to the kill ring, you have access to a ring of your past secondary selections.

    And if you use library second-sel.el and Icicles then M-y yanks an entry from the the ring you last yanked from (kill ring or secondary-selection ring).

    And if you use library browse-kill-ring+.el then the kill-ring browser gives you access to an alternative ring also (which, by default, is the ring of secondary selections if you use library second-sel.el).


See also the other answers to the S.O. question - using a register, for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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