I want to overwrite text by yank as following. Is there any way to do this?
kill-ring:
text-i-want-to-paste
Before:
abcdefghijklmnopqrstuvwxyz
^
corsor
After:
text-i-want-to-pasteuvwxyz
I want to overwrite text by yank as following. Is there any way to do this?
kill-ring:
text-i-want-to-paste
Before:
abcdefghijklmnopqrstuvwxyz
^
corsor
After:
text-i-want-to-pasteuvwxyz
Turn on delete-selection-mode
. Then select the text to replace. Then hit C-y
. With delete-selection-mode
enabled, you just type to replace selected text, as is usual outside Emacs. And C-y
also replaces it.
You can also use defadvice. Then this will only work when overwrite-mode is on:
(defadvice yank (before yank-if-overwrite)
(if (bound-and-true-p overwrite-mode)
(delete-char (length (current-kill 0))))
)
(ad-activate 'yank)
Here:
(defun crazy-yank ()
(interactive)
(delete-char (length (current-kill 0)))
(yank))
(global-set-key (kbd "C-M-y") 'crazy-yank)
© 2022 - 2024 — McMap. All rights reserved.