In Evil mode, is it possible to prevent change and deletion commands from putting the replaced object into the selection (system clipboard)? I would like yanking to still do so.

I'd like to be able to yank an object (or copy it in another application), then move to the destination, press cw to replace it, and press Cmd-V to paste the source text. The standard behaviour is for all yank, change, and deletion to go to the unnamed register, which is also used for pasting, which means that I have to resort to "viwp" or "cwC-r 0".

2 Answers 2


Evil doesn't support this out of the box, but Emacs’ advice feature will let you get what you want.

Simplifying a lot, evil-change calls evil-delete and evil-delete calls evil-yank then delete-region. delete-region does not mess with the clipboard, so one solution is to modify what evil-yank does within evil-delete. For purposes of this example I’m going to make evil-yank a no-op when it’s called from evil-delete. I’m doing this by defining an appropriate wrapper function then using advice-add to wrap evil-delete.

(defun my-yank-is-noop-wrapper (orig-fun &rest args)
  (cl-letf (((symbol-function 'evil-yank) #'ignore))
    (apply orig-fun args)))

(advice-add 'evil-delete :around #'my-yank-is-noop-wrapper)

You can get more creative with advice. For instance, you could filter the arguments before they go into evil-delete (like, you could check the value of the register argument and set it to something.) For this next example I’m just going to make evil-delete message you about its arguments; you can tweak the code to do whatever you want.

(defun my-filter-arguments (args)
  (message "Args: %s" args)
  ;; do something to args here
  ;; the advised function sees the result of this function
  ;; so be sure to return an args list

(advice-add 'evil-delete :filter-args #'my-filter-arguments)

Advice can be really hard to debug if it misbehaves, though! Keep that advice-remove handy if things get weird!


It's not possible by looking at evil-change and at evil-visual-paste as they explicitly call evil-delete (or evil-delete-line)

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.