14

Is it possible to retrieve changes branch that I "abandoned"? For example, I am undoing several operations using u, then I am making a change in insert mode. But then I realize I don't want to have this change, I would rather go back to where I was at the beginning (before undoing).

Are these changes lost forever?

12

For navigating the undo tree your best bet is to use the Gundo plugin. This creates a new split window with special bindings to jump to different branches within the undo tree as well as a preview pane that shows you exactly what changed between each node in the tree.

  • Another choice would be UndoTree. – musicmatze Feb 4 '15 at 0:28
12

For simple cases like this, you can simply press g-.

Essentially, what this does is traverse the change list chronologically (treating a u as an actual change), rather than linearly (like with u/<C-r>).

For example, if you've inserted a few lines, and you press g-, this happens:

demonstration

  • how did you create the animated gif? – guido Feb 3 '15 at 22:32
  • 4
    @guido I used a custom tool called mkcast. – Doorknob Feb 3 '15 at 22:34
2

No, you cannot go back and forward in the tree. The best way is to use a plugin to this job.

Another plugin is the Undotree. It's like Gundo, but with some differences:

  1. Pure vimscript implementation and no 3rd-party libraries(like python) is needed, don't worry about performance, it's not such a big deal for vim to handle this. The only dependency is the 'diff' tool which always shipped with vim and even without 'diff' you still can use most of the features of this script.
  2. Realtime updated undo tree. Once you make changes, the undo tree will be updated simultaneously.
  3. Several useful marks, like current changeset, next redo changeset, saved changeset, etc.
  4. Toggle between relative timestamp and absolute timestamp.
  5. Realtime updated undo window.
  6. Ability to clear undo history.
  7. More customizable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.