Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite text by yank in Emacs?

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

Thanks.

like image 677
Kei Minagawa Avatar asked Feb 27 '14 16:02

Kei Minagawa


2 Answers

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.

like image 112
Drew Avatar answered Oct 01 '22 10:10

Drew


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)
like image 21
nopede11 Avatar answered Oct 01 '22 10:10

nopede11