如何在 Vim 中删除(所需文本)、删除(不需要的文本)和粘贴(所需文本)

发布于 2024-08-21 17:35:40 字数 129 浏览 4 评论 0原文

我不知道这是否是一个弱智问题,但这是一个有趣的困境。当我想删除我想放在其他地方的文本,但那个地方有其他一堆我不想要的文本时,我会删除该文本,但在此过程中我复制一个新的剪贴板,以便以前删除的文本消失。

有什么建议来解决这个问题吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

酷炫老祖宗 2024-08-28 17:35:41

一些可能的解决方案:

首先删除不需要的文本:)

删除所需文本时,将其存储在默认寄存器之外的寄存器中,例如将所需文本删除到当前行末尾并将其存储在寄存器b中:

"bd$

然后删除不需要的文本。

然后粘贴寄存器的内容b

"bp

按照Yarek T 使用:

"_d

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
难以启齿的温柔 2024-08-28 17:35:41

也许这个问题可能会阐明您的问题。 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.

捂风挽笑 2024-08-28 17:35:41

另一种解决方案是使用数字寄存器。当您删除一块文本时,它会移入寄存器 1,寄存器 1 的当前内容会移入寄存器 2,依此类推。寄存器 9 的内容将被丢弃。然而,这仅适用于长度超过一行的更改,因此不会捕获小的删除。

因此,您可以删除第一个区域,删除第二个区域,然后从寄存器 2 粘贴。

我个人更喜欢使用寄存器 az,但是如果您删除一些文本然后意识到忘记指定寄存器,则编号的寄存器会很有用。

执行 :help "1 获取更多信息。

您还可以使用 :registers 查看所有寄存器中当前的内容,包括 1-9

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

最美的太阳 2024-08-28 17:35:41

键入:

:registers

您将获得包含所有先前删除的寄存器列表。您随时可以选择一个进行粘贴。例如,对于寄存器:

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

选择第二个并将其粘贴为:

"2p

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
孤星 2024-08-28 17:35:41

尝试使用 yankring 插件。

Try the yankring plugin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文