Home Explore Blog CI



neovim

3rd chunk of `runtime/doc/undo.txt`
cce670050646d377a487bfe95371459d6c8755b77b73e6b40000000100000fa1
 identify a
			specific undo-able change, see |:undo|.
			The "changes" column is the number of changes to this
			leaf from the root of the tree.
			The "when" column is the date and time when this
			change was made.  The four possible formats are:
			    N seconds ago
			    HH:MM:SS             hour, minute, seconds
			    MM/DD HH:MM:SS       idem, with month and day
			    YYYY/MM/DD HH:MM:SS  idem, with year
			The "saved" column specifies, if this change was
			written to disk and which file write it was. This can
			be used with the |:later| and |:earlier| commands.
			For more details use the |undotree()| function.

							*g-*
g-			Go to older text state.  With a count repeat that many
			times.
							*:ea* *:earlier*
:ea[rlier] {count}	Go to older text state {count} times.
:ea[rlier] {N}s		Go to older text state about {N} seconds before.
:ea[rlier] {N}m		Go to older text state about {N} minutes before.
:ea[rlier] {N}h		Go to older text state about {N} hours before.
:ea[rlier] {N}d		Go to older text state about {N} days before.

:ea[rlier] {N}f		Go to older text state {N} file writes before.
			When changes were made since the last write
			":earlier 1f" will revert the text to the state when
			it was written.  Otherwise it will go to the write
			before that.
			When at the state of the first file write, or when
			the file was not written, ":earlier 1f" will go to
			before the first change.

							*g+*
g+			Go to newer text state.  With a count repeat that many
			times.
							*:lat* *:later*
:lat[er] {count}	Go to newer text state {count} times.
:lat[er] {N}s		Go to newer text state about {N} seconds later.
:lat[er] {N}m		Go to newer text state about {N} minutes later.
:lat[er] {N}h		Go to newer text state about {N} hours later.
:lat[er] {N}d		Go to newer text state about {N} days later.

:lat[er] {N}f		Go to newer text state {N} file writes later.
			When at the state of the last file write, ":later 1f"
			will go to the newest text state.


Note that text states will become unreachable when undo information is cleared
for 'undolevels'.

Don't be surprised when moving through time shows multiple changes to take
place at a time.  This happens when moving through the undo tree and then
making a new change.

EXAMPLE

Start with this text:
	one two three ~

Delete the first word by pressing "x" three times:
	ne two three ~
	e two three ~
	 two three ~

Now undo that by pressing "u" three times:
	e two three ~
	ne two three ~
	one two three ~

Delete the second word by pressing "x" three times:
	one wo three ~
	one o three ~
	one  three ~

Now undo that by using "g-" three times:
	one o three ~
	one wo three ~
	 two three ~

You are now back in the first undo branch, after deleting "one".  Repeating
"g-" will now bring you back to the original text:
	e two three ~
	ne two three ~
	one two three ~

Jump to the last change with ":later 1h":
	one  three ~

And back to the start again with ":earlier 1h":
	one two three ~


Note that using "u" and CTRL-R will not get you to all possible text states
while repeating "g-" and "g+" does.

==============================================================================
5. Undo persistence		*undo-persistence* *persistent-undo*

When unloading a buffer Vim normally destroys the tree of undos created for
that buffer.  By setting the 'undofile' option, Vim will automatically save
your undo history when you write a file and restore undo history when you edit
the file again.

The 'undofile' option is checked after writing a file, before the BufWritePost
autocommands.  If you want to control what files to write undo information
for, you can use a BufWritePre autocommand: >
	au BufWritePre /tmp/* setlocal noundofile

Vim saves undo trees in a separate undo file, one for each edited file, using
a simple scheme that maps filesystem paths directly to undo files. Vim will
detect if an undo file is no longer synchronized with the file it was written
for (with a hash of the file contents)

Title: Navigating Undo Branches and Persistent Undo
Summary
This section details the ':undolist' command for listing undo tree leaves and the 'g-' and 'g+' commands for navigating older and newer text states, respectively. It also describes the ':earlier' and ':later' commands, which allow moving through text states by count, time, or file writes. The section includes an example of using these commands to navigate undo branches. Furthermore, it explains the 'undofile' option for persistent undo, which saves and restores undo history across Vim sessions.