How to rewrite text with yank in Emacs?

I want to rewrite yank text as follows. Is there any way to do this?

kill the ring:

text-i-want-to-paste 

Before:

 abcdefghijklmnopqrstuvwxyz ^ corsor 

After:

 text-i-want-to-pasteuvwxyz 

Thanks.

+6
source share
3 answers

Enable delete-selection-mode . Then select the text to replace. Then press Cy . With delete-selection-mode enabled, you simply type in text that replaces the selected text, as is usually the case outside Emacs. And Cy also replaces it.

+7
source

You can also use defadvice. Then this will only work when rewritable mode is enabled:

 (defadvice yank (before yank-if-overwrite) (if (bound-and-true-p overwrite-mode) (delete-char (length (current-kill 0)))) ) (ad-activate 'yank) 
+4
source

Here:

 (defun crazy-yank () (interactive) (delete-char (length (current-kill 0))) (yank)) (global-set-key (kbd "CMy") 'crazy-yank) 
+3
source

All Articles