Home Explore Blog CI



neovim

2nd chunk of `runtime/doc/usr_32.txt`
ee8f8f606ac0603c0475ecb8240cc9be627c23f49525be010000000100000e59
 append
" too".  And then move to the first 'o' and change it into 'w'.  We then have
two changes, numbered 1 and 2, and three states of the text:

		one ~
		 |
	      change 1
		 |
	      one too ~
		 |
	      change 2
		 |
	      one two ~

If we now undo one change, back to "one too", and change "one" to "me" we
create a branch in the undo tree:

		one ~
		 |
	      change 1
		 |
	      one too ~
	      /     \
	 change 2  change 3
	    |	      |
	 one two    me too ~

You can now use the |u| command to undo.  If you do this twice you get to
"one".  Use |CTRL-R| to redo, and you will go to "one too".  One more |CTRL-R|
takes you to "me too".  Thus undo and redo go up and down in the tree, using
the branch that was last used.

What matters here is the order in which the changes are made.  Undo and redo
are not considered changes in this context.  After each change you have a new
state of the text.

Note that only the changes are numbered, the text shown in the tree above has
no identifier.  They are mostly referred to by the number of the change above
it.  But sometimes by the number of one of the changes below it, especially
when moving up in the tree, so that you know which change was just undone.

==============================================================================
*32.3*	Jumping around the tree

So how do you get to "one two" now?  You can use this command: >

	:undo 2

The text is now "one two", you are below change 2.  You can use the |:undo|
command to jump to below any change in the tree.

Now make another change: change "one" to "not":

		one ~
		 |
	      change 1
		 |
	      one too ~
	      /     \
	 change 2  change 3
	    |	      |
	 one two    me too ~
	    |
	 change 4
	    |
	 not two ~

Now you change your mind and want to go back to "me too".  Use the |g-|
command.  This moves back in time.  Thus it doesn't walk the tree upwards or
downwards, but goes to the change made before.

You can repeat |g-| and you will see the text change:
	me too ~
	one two ~
	one too ~
	one ~

Use |g+| to move forward in time:
	one ~
	one too ~
	one two ~
	me too ~
	not two ~

Using |:undo| is useful if you know what change you want to jump to.  |g-| and
|g+| are useful if you don't know exactly what the change number is.

You can type a count before |g-| and |g+| to repeat them.

==============================================================================
*32.4*	Time travelling

When you have been working on text for a while the tree grows to become big.
Then you may want to go to the text of some minutes ago.

To see what branches there are in the undo tree use this command: >

	:undolist
<	number changes  time ~
	     3       2  16 seconds ago
	     4       3  5 seconds ago

Here you can see the number of the leaves in each branch and when the change
was made.  Assuming we are below change 4, at "not two", you can go back ten
seconds with this command: >

	:earlier 10s

Depending on how much time you took for the changes you end up at a certain
position in the tree.  The |:earlier| command argument can be "m" for minutes,
"h" for hours and "d" for days.  To go all the way back use a big number: >

	:earlier 100d

To travel forward in time again use the |:later| command: >

	:later 1m

The arguments are "s", "m" and "h", just like with |:earlier|.

If you want even more details, or want to manipulate the information, you can
use the |undotree()| function.  To see what it returns:
>
	:echo undotree()
<
==============================================================================

Next chapter: |usr_40.txt|  Make new commands

Copyright: see |manual-copyright|  vim:tw=78:ts=8:noet:ft=help:norl:

Title: Navigating and Time Traveling in Vim's Undo Tree
Summary
This section explains how to move around the undo tree in Vim. It demonstrates how to use the `:undo` command to jump to specific changes, and the `g-` and `g+` commands to move backward and forward in time. It also covers using `:undolist` to view the undo tree branches and their timestamps, and `:earlier` and `:later` to travel through time based on specific time intervals (seconds, minutes, hours, days).