tags:

views:

98

answers:

2

Hi,

Does there exist a register, option... to get the last word deleted (dw)?

Suppose that I have this line:

word_1, word_2, word_3

I place the cursor on w of word_2 and dw and I get:

word_1, , word_3

So I press xx to delete the , followed by a space.

I can't use p or P to paste word_2 because it contains a space.

I know that I could use a register to copy word_2 into it and use " to paste word_2.

Thanks

=============================================

EDIT

While googling

delete register vim

I found this interesting related question: In vim is there a way to delete without putting text in the register?

+4  A: 

For small deletes inside one line, like deleting a word or removing single characters with x, no multi-level history is stored in registers.

For larger deletes (one line or more, or some special movement commends) the last nine deleted items are automatically stored in the registers 1 to 9. So if you do three deletes you can paste the text from the first one (third item in the history) with "3p.

For the official documentation for these registers see also :help quote_number.

sth
Many thanks. I was looking for descriptions for each available register.
Luc M
Thanks, refined my answer.
Antony Hatchkins
+2  A: 

There is only one register keeping the data deleted within a line : "" (well there is also "- but it is of little use here since it is a copy of "" in this case). [text in italic added afterwards]

It is definitely not the universal solution, but I have remapped x to "delete to nowhere":

:map x "_d
:map xx "_dd

This way d deletes to delete register and x does the same but doesn't litter delete register, so that I can keep valuable deleted information intact.

So in your case I would type: dw 2x<Right> (or xf<Space>) and then p

Antony Hatchkins