如何在 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一些可能的解决方案:
首先删除不需要的文本:)
或
删除所需文本时,将其存储在默认寄存器之外的寄存器中,例如将所需文本删除到当前行末尾并将其存储在寄存器b中:
然后删除不需要的文本。
然后粘贴寄存器的内容b:
或
按照Yarek T 使用:
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:
Then delete your undesired text.
Then paste the contents of register b:
or
Delete the undesired text to the black hole register as suggested in the answer linked to by Yarek T using:
也许这个问题可能会阐明您的问题。 54255
它使用“黑洞缓冲区”来删除行而不将它们添加到复制缓冲区中。
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.
另一种解决方案是使用数字寄存器。当您删除一块文本时,它会移入寄存器 1,寄存器 1 的当前内容会移入寄存器 2,依此类推。寄存器 9 的内容将被丢弃。然而,这仅适用于长度超过一行的更改,因此不会捕获小的删除。
因此,您可以删除第一个区域,删除第二个区域,然后从寄存器 2 粘贴。
我个人更喜欢使用寄存器 az,但是如果您删除一些文本然后意识到忘记指定寄存器,则编号的寄存器会很有用。
执行
:help "1
获取更多信息。您还可以使用
:registers
查看所有寄存器中当前的内容,包括 1-9Another 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:
And you'll get a list of registers that contain all previous deletions. You can always pick one to paste. E.g. for registers:
pick the second one and paste it with:
尝试使用 yankring 插件。
Try the yankring plugin.