2

If I have text1 text2, I yank text1 with yw then I highlight text2 with vw and paste overwrite that text with p, my kill ring now has text2. I'd prefer if text2 wasn't added to my kill ring because next time I paste text, Emacs will paste text2 which I inadvertently copied.

Same question for x (which deletes 1 character), the deleted character goes into my kill ring.

p then C-p to cycle through the kill ring isn't ideal. I paste the text again, the over written text is continually added onto the kill ring leading to more C-p presses to get the original text. Ideally I'm hoping to disable or redefine p when over writing text to not add to the kill ring

2

After yank text1, the text is saved in both register " and 0:

  "" text1
  "0 text1
  "1 ...

When paste with p, you actually got text1 from register ", at the same time, the killed text is saved in ":

  "" text2
  "0 text1
  "1 ...

So, if you want paste text1 next time, you should press "0p instead of p, or replace the default key binding:

(defun evil-paste-after-from-0 ()
  (interactive)
  (let ((evil-this-register ?0))
    (call-interactively 'evil-paste-after)))

(define-key evil-visual-state-map "p" 'evil-paste-after-from-0)
  • 3
    Please add some explanations, such as an idea of how the code works, and what other effects it might have. – Stefan Apr 24 '17 at 18:23
  • What Stefan said. – JeanPierre Apr 27 '17 at 19:53
  • Can we go a bit farther and put the contents in another register incase we DO want to use the killed text? i.e. put the contents in the " register? – irregular Jun 6 '17 at 15:07
  • @Stefan explanations added – gongqj Jun 7 '17 at 3:48
  • 1
    @irregular ""p can get the killed text – gongqj Jun 7 '17 at 3:49
0

I'm pretty new to emacs, so I'm not sure about the terminology, but using vim-speak (and this works in evil-mode), yanking populates the 0 register, while deleting text will populate the 1-9 registers, pushing them along as you delete text. So in your case, you should be able to access your yanked text using "0p, even after deleting something else.

  • That's right and would definitely work. With Emacs though you would want to customize the functionality to make your workflow more efficient. In this case I'd want to either copy the function and eliminate adding to the kill-ring (where all pasted/deleted text goes for future access) or a function that adds to the register like you say so that under the hood p actually stores in a register. These are a bit difficult for me as well as I'm also not an expert but there's the case of considering normal p usage i.e. when not pasting over visually selected text – irregular Oct 27 '16 at 4:11
0

The suggestion in @gongqj's answer changes the behavior of paste so that cut text (via d) no longer gets pasted. This does not seem like what you want given your comment:

Ideally pasted over text is not added to the kill ring but we get killed text (not from pasting over, i.e. D) then it'd be nice to paste that on visual state paste.

If your real goal is to avoid adding the replaced text to the kill ring upon pressing p, you could add the following:

(setq-default evil-kill-on-visual-paste nil)

The relevant lines are in the evil-visual-paste definition in evil-commands:

(when evil-kill-on-visual-paste
  (kill-new new-kill))

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.