So I usually find myself copying text from one point to another while overwriting old text where the new is pasted:
blah1
newtext
blah2
wrong1
blah3
wrong2
blah4
Suppose I visual-mark newtext and yank it. Now I select wrong1 (which could be anything, not necessarily just a word) and paste the newtext. However, if I now do the same with wrong2 it will be replaced with wrong1 instead of newtext.
So how do I keep the text that is in the buffer from being swapped with the text that I am currently overwriting?
Edit 1
Although I quite like the reigister suggestions (I think I will start using registers more, now that I discovered the :dis command), I am going with a modification of jinfield's answer, because I do not use the swapping mode.
vnoremap p "0p
vnoremap P "0P
vnoremap y "0y
vnoremap d "0d
does the trick perfectly.
Edit 2
I was too fast; romainl's solution is precisely what I was looking for, without the hack in Edit 1.
Actually, vnoremap p "_dP is enough!
So, changing accepted answer.
Answer
I have these mappings in my .vimrc:
" delete without yanking
nnoremap d "_d
vnoremap d "_d
" replace currently selected text with default register
" without yanking it
vnoremap p "_dP
"_ is the "blackhole register", according to :help "_:
"When writing to this register, nothing happens. This can be used to delete text without affecting the normal registers. When reading from this register, nothing is returned. {not in Vi}"
No comments:
Post a Comment