Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the undo tree used in Vim?

Tags:

undo

vim

People also ask

What is undo in Vim?

To undo a change in Vim/Vi type u , and to redo a change which was undone use the Ctrl-R key sequence. Vim also supports undo branches .

How many times can you use the vim undo command?

2 Answers. Show activity on this post. You have only 1 level of undo if you are in Vi compatible mode. You are missing out on a number of features by being in 'compatible' mode.

Which command is used to undo the previuos steps?

To undo an action press Ctrl+Z. If you prefer your mouse, click Undo on the Quick Access Toolbar. You can press Undo (or CTRL+Z) repeatedly if you want to undo multiple steps.


See also :h undo-redo, which lists all the commands and their usage.

There are two ways to traverse the undo tree. One is to go "back in time". g+ and g- will traverse all of the nodes in the tree in chronological or reverse-chronological order (which can be a bit confusing, because it can jump arbitrarily between undo branches, but if you do g- long enough you'll always get where you need to go eventually). :earlier and :later take a time descriptor like 7m or 1h; again this can jump you arbitrarily between undo branches.

The other way is to jump to specific nodes in the tree using :undo n where n is a number of an action. (All actions, i.e. text additions, deletions, replacements, are numbered sequentially as you do them.) You can look up the number of the actions on the leaves of the undo tree via :undolist. This will let you jump between branches easily. You can then use u and Ctrl-R to move up and down that branch.

There are some good examples in the Vim help. The best way to figure out how this works is to play with it a bit.


I'm a bit late to the party,
but I figured I'd mention that I wrote an undo tree visualization plugin for Vim :
https://github.com/sjl/gundo.vim

Personally I found that graphing the tree like this was the only way I could make sense of it.


This page explains everything you need to know:

http://vimdoc.sourceforge.net/htmldoc/usr_32.html


If you're using vim, you can navigate through the undo tree using:

  • u: (undo) move back in the undo tree
  • Ctrl+R: (redo) move forward in the undo tree

Other ways of bringing document back or forward in time:

  • :earlier 15m: move back in time 15 minutes
  • :later 15m: move front in time 15 minutes