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
args)
(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!