Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 316
Kevin Burke Avatar asked Apr 24 '11 21:04

Kevin Burke


People also ask

How do you CTRL-Z in Vim?

on linux, CTRL-Z in vi/vim/gvim mean escape to the console, or put this in the background. you then do whatever you want on the console and type fg (foreground) to bring you back into vim edit session.

How do I undo a forward in Vim?

Undo Changes in Vim / Vi Press esc to return to normal mode. Any character typed in normal mode will be interpreted as a vim command. Press u, :u, or :undo to undo the last change (entry).

How many times can you use the Vim undo command?

You have only 1 level of undo if you are in Vi compatible mode.


1 Answers

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

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

like image 69
Nick Knowlson Avatar answered Sep 23 '22 12:09

Nick Knowlson