Search code examples
vimtreeundo3-way-merge

Skip undo step in 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.


Solution

  • 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 :)