How to overwrite text by yank in Emacs?
Asked Answered
C

3

7

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
Covenant answered 27/2, 2014 at 16:14 Comment(0)
A
8

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.

Antichlor answered 27/2, 2014 at 17:2 Comment(0)
D
6

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)
Disillusionize answered 15/7, 2014 at 17:12 Comment(0)
P
5

Here:

(defun crazy-yank ()
  (interactive)
  (delete-char (length (current-kill 0)))
  (yank))

(global-set-key (kbd "C-M-y") 'crazy-yank)
Preciousprecipice answered 27/2, 2014 at 16:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.