How to delete (not cut) in Vim?

Viewed 70187

How can I delete a line without putting it into my default buffer?

Example:

line that will be copied.

line that I want to be substitued with the previous one.

What I'm trying to do:

yy
dd
p

But Vim replaces the recent copied string with the deleted (cutted) one. I know that I can use buffers like, "1yy, dd then "1p, but I always forget to put the copied string in a buffer then I need to paste my contents first (line that will be copied) and then delete what I want (line that I want to be substituted with the previous one.)

How can I really delete a text in Vi(m) without copying it?

Another related question is how I can forward delete a word in insert mode? I want something similar to Ctrl+w.

8 Answers

I use noremap ' "_ in my .vimrc

This keep the behavior of dd, so I can use it to cut as before.

But when I really want to delete something, just use the prefix '. For example: 'dd,'dw

I ended up with

nnoremap p "0p
nnoremap P "0P
vnoremap p "0p
vnoremap P "0P
vnoremap x "0x
nnoremap x "0x

Always paste from the 0 register instead of the unnamed one. Use x in visual mode to delete into the 0 register.

yy
Vx
p

When in visual mode, x will delete the selection, so if you want to delete a whole line, first press V to select the line in visual mode and then press x to delete the selection.

Related