J-Win
J-Win

Reputation: 1492

Vim - don't delete upon visual paste

Copying a word into a register, selecting a different word with visual mode, and pasting over the second word deletes the original word in the register.

For example, running vey on Word_1, then running vep on Word_2 now puts Word_2 in the "* register. I would like the "* register to maintain the Word_1 value. Any ideas?

I was thinking of mapping paste in visual mode to a custom range function, saving the register before pasting, and then restoring the register after pasting. I just need some help doing that.

Upvotes: 1

Views: 137

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172618

I need this so often, I wrote a plugin to simplify and allow maximum speed: ReplaceWithRegister.

This plugin offers a two-in-one gr command that replaces text covered by a {motion} / text object, entire line(s) or the current selection with the contents of a register; the old text is deleted into the black-hole register, i.e. it's gone. It transparently handles many corner cases and allows for a quick repeat via the standard . command. Should you not like it, its page has links to alternatives.

Upvotes: 2

mattn
mattn

Reputation: 7723

Try to install vim-operator-user and vim-operator-replace

Upvotes: 1

Related Questions