Copy, delete, then paste in Vim
Solution 1:
Take a look at :h copy-move
. The default yank or delete goes into a place called a register (a register named "
). If you need to delete some text before you paste, you need to avoid overwriting register x, as you've discovered. Fortunately, you can use any other letter or number to name a different register.
-
"ayy
(yank a line into registera
) -
x
,dd
, etc. (delete some text into the unnamed register,"
) -
"ap
(paste the text from registera
)
Solution 2:
If the problem is that you merely need to replace some text
with some text2
, then, just highlight and yank text2
. Then highlight text
and press p
or P
to paste text2
in place of text
.
A quick further guide for some common vim commands is http://www.catswhocode.com/blog/100-vim-commands-every-programmer-should-know
Enjoy!
Edit: note that p
pastes text after the cursor and P
before the cursor.