开发者

How to Delete (desired text), delete (undesired text), and paste (desired text) in Vim

I don't know if its a retarded problem but it's a funny dilemma. When I want to delete text that I want开发者_运维知识库 to place somewhere else, but that place has other bunch of text that I don't want, I would delete that text, but in the process I copy a new clipboard so the previously deleted text disappear.

Any suggestions to solve this?


A few possible solutions:

Delete the undesired text first :)

or

When deleting the desired text store it in a register other than the default register e.g. to delete the desired text to the end of the current line and store it in register b:

"bd$

Then delete your undesired text.

Then paste the contents of register b:

"bp

or

Delete the undesired text to the black hole register as suggested in the answer linked to by Yarek T using:

"_d


maybe this question might shed some light onto your problem. 54255

It uses the "black hole buffer" to delete lines without adding them to the yank buffer.


Another solution is to use the number registers. When you delete a chunk of text it is moved into register 1, the current contents of register 1 is moved into register 2, etc. The contents of register 9 are discarded. However this only works for changes longer than a line, so small deletes are not captured.

So you can delete the first region, delete the second region, then paste from register 2.

Personally I prefer to use registers a-z, but the numbered registers are useful if you delete some text and then realise you forgot to specify a register.

Do :help "1 for more information.

You can also see what is currently in all the registers, including 1-9, with :registers


Type:

:registers

And you'll get a list of registers that contain all previous deletions. You can always pick one to paste. E.g. for registers:

"1   Item1^J
"2   Item3^J
"3   Item2^J

pick the second one and paste it with:

"2p


Try the yankring plugin.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜