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

人走茶凉 提交于 2019-12-03 16:22:28
mikej

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
Yarek T

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!