在 Vim 中跳过撤消步骤

发布于 2024-11-03 07:07:13 字数 237 浏览 5 评论 0原文

假设我的文档处于状态 A。然后我(按顺序)进行更改 B、C 和 D。

有没有办法可以保留更改 B 和 D,但跳过 C?

或者,假设我的文档处于状态 A。我进行更改 B,撤消它,然后进行更改 C 和 D(因此 Vim 有一个具有两个分支的撤消树)。然后我改变主意并决定使用 B 和 D 而不是 C。

我如何在 Vim 中做到这一点?我安装了 gundo.vim 插件,但我没有经常使用它。

Let's say I'm at state A in my document. I then make changes B, C, and D (in order).

Is there a way I can keep changes B and D, but skip C?

Or, let's say I'm at state A in my document. I make change B, undo it, and then make changes C and D (so Vim has an undo tree with two branches). I then change my mind and decide I want to use B and D but not C.

How can I do this in Vim? I have the gundo.vim plugin installed, but I haven't used it that much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

故事和酒 2024-11-10 07:07:13

好吧,我会尝试一下并说:不,我认为没有办法用 vim 完全满足您的要求。

gundo.vim 为 vim 的撤消功能添加了一个漂亮的界面,但没有改变其核心功能。所以我查看了 vim 官方文档,看看是否有任何提示说明它是否能够做到这一点:

没有关于将两个分支合并在一起。我认为 ewh 和 ZyX 是正确的:为了获得将 B 与 D 合并的通用解决方案,vim 需要

  1. Bram 将其作为单独的功能添加到未来版本中,
  2. 或者通过与已经可以使用的东西集成来在插件中实现它进行合并(如 git/hg)

您当然可以尝试通过打开版本 B、C 和 D 的文件以及一些差异来手动进行合并。


注意:如果我误解了,并且您并不想知道通用解决方案并且正在寻求有关此特定实例的帮助,请告诉我,我会看看我能做什么:)

Well, I'll take a stab at this and say: No, I don't think there's a way to do exactly what you want with vim.

gundo.vim adds a nice interface to vim's undo, but doesn't change its core capabilities. So I took a look at the official vim docs to see if there's any hints to whether it is capable of this:

Nothing about merging two branches together. I think ewh and ZyX are right: to get a general solution for merging B with D, vim would need either for

  1. Bram to add it as a separate feature in a future version
  2. someone to implement it in a plugin by integrating with something that can already do merges (like git/hg)

You can of course try to do it manually by having files with versions B, C and D as well as a few diffs open.


Note: If I misunderstood and you weren't wondering about a general solution and are looking for help with a specific instance of this, let me know and I'll see what I can do :)

千仐 2024-11-10 07:07:13

有没有办法可以保留更改 B 和 D,但跳过 C?

您处于状态 D。 :w file.ext_D

返回到状态 C。 :w file_ext_C

返回到状态 B。 :w file.ext_B

:!kdiff3 file.ext_B file.ext_C file.ext_D

这提供了差异的 3 路合并,但您仍然必须手动进入并为每个合并冲突选择 D 中的每条红线。这不完全是一个简单的解决方案。

相反,如果您这样做

:!kdiff3 file.ext_C file.ext_B file.ext_D

,那么合并会自动发生(除了具有多个更改的单行)

对于更复杂的情况,它会变得更加困难。

注意:我不确定版本控制工具有什么帮助。您基本上是在做一些事情,例如在 B 和 D 之间创建补丁,然后从中减去从 C 到 D 的补丁。在我看来,修订控制系统通常旨在管理不同变更源之间的合并,而不是管理单个分支的变更。

kdiff3 位于:http://kdiff3.sourceforge.net/

Is there a way I can keep changes B and D, but skip C?

You're at state D. :w file.ext_D

Backtrack to state C. :w file_ext_C

Backtrack to state B. :w file.ext_B

:!kdiff3 file.ext_B file.ext_C file.ext_D

This gives a 3 way merge of the differences, but still you'd have to manually go in and choose every red line in D for each merge conflict. Not exactly an easy solution.

If instead you do

:!kdiff3 file.ext_C file.ext_B file.ext_D

Then the merge happens automatically (except for individual lines with multiple changes)

For more complicated scenarios it gets tougher.

Note: I'm not sure how a revision control tool is much help. You're basically doing something like creating a patch between B and D, and then subtracting the patch from C to D from it. It seems to me that revision control systems are usually designed to manage merges between different sources of changes, not changes along a single branch.

kdiff3 is available at: http://kdiff3.sourceforge.net/

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