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

4 Answers 4


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 ()
  (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, 2017 at 18:23
  • What Stefan said.
    – JeanPierre
    Apr 27, 2017 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, 2017 at 15:07
  • @Stefan explanations added
    – gongqj
    Jun 7, 2017 at 3:48
  • 1
    @irregular ""p can get the killed text
    – gongqj
    Jun 7, 2017 at 3:49

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))
  • 1
    While @gongqj's answer is educational, this answer is the one that I really want.
    – user25410
    Dec 10, 2019 at 20:51

Here is my solution: Press xP to paste over the region without changing the kill ring.

(define-key evil-normal-state-map "x" 'delete-forward-char)     ; delete to the black hole
(define-key evil-normal-state-map "X" 'delete-backward-char)

Explanation in details: https://emacs.stackexchange.com/a/53536/18298


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, 2016 at 4:11

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.