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 m开发者_Python百科y 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.
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:
- vim docs: undo
- User manual page about undo
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
- Bram to add it as a separate feature in a future version
- 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 :)
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/
精彩评论