How to delete (not cut) in Vim?
The black hole register "_
will do the trick, but there is a better solution:
When you enter the line back with the p
command you are pasting the contents of the (volatile) default register ""
, which has been overwritten by dd
. But you still can paste from the (non volatile) yank register "0
, which won't be overwritten by the delete command dd
.
So these are the commands you want to use as per your example:
yy
dd
"0p
Use the "black hole register", "_
to really delete something: "_d
.
Use "_dP
to paste something and keep it available for further pasting.
For the second question, you could use <C-o>dw
. <C-o>
is used to execute a normal command without leaving the insert mode.
You can setup your own mappings to save typing, of course. I have these:
nnoremap <leader>d "_d
xnoremap <leader>d "_d
xnoremap <leader>p "_dP