Nvim :help
pages, generated
from source
using the tree-sitter-vimdoc parser.
:u
:un
:undo
:u[ndo] Undo one change.
E830
:u[ndo] {N}
Jump to after change number {N}
. See undo-branches
for the meaning of {N}
.E5767
:u[ndo]! {N}
Like ":u[ndo] {N}
", but forget all changes in the
current undo branch up until {N}
. You may only use
":undo! {N}
" to move backwards in the same undo
branch, not to redo or switch to a different undo
branch.CTRL-R
CTRL-R Redo [count] changes which were undone.U
U Undo all latest changes on one line, the line where
the latest change was made. U itself also counts as
a change, and thus U undoes a previous U.CTRL-R
' command redoes it again. When
mixing "U", "u" and 'CTRL-R
' you will notice that the "U" command will
restore the situation of a line to before the previous "U" command. This may
be confusing. Try it out to get used to it.
The "U" command will always mark the buffer as changed. When "U" changes the
buffer back to how it was without changes, it is still considered changed.
Use "u" to undo changes until the buffer becomes unchanged.CTRL-R
" no-op two times undoCTRL-R
. Unfortunately, this
is not Vi compatible. For example "dwdwu." in Vi deletes two
words, in Nvi it does nothing.:undoj
:undojoin
E790
:undoj[oin] Join further changes with the previous undo block.
Warning: Use with care, it may prevent the user from
properly undoing changes. Don't use this after undo
or redo.:undojoin | deleteAfter this a "u" command will undo the delete command and the previous change.
undo-break
undo-close-block
To do the opposite, use a new undo block for the next change, in Insert mode
use CTRL-G
u. This is useful if you want an insert command to be undoable in
parts. E.g., for each sentence. i_CTRL-G_ug:undolevels
to explicitly read
and write only the global value of 'undolevels'.let &g:undolevels = &g:undolevelsNote that the similar-looking assignment
let &undolevels=&undolevels
does not
preserve the global option value of 'undolevels' in the event that the local
option has been set to a different value. For example:" Start with different global and local values for 'undolevels'. let &g:undolevels = 1000 let &l:undolevels = 2000 " This assignment changes the global option to 2000: let &undolevels = &undolevels
:undol
:undolist
:undol[ist] List the leafs in the tree of changes. Example:
g-
g- Go to older text state. With a count repeat that many
times.
:ea
:earlier
:earlier {count}
Go to older text state {count}
times.
:earlier {N}
s Go to older text state about {N}
seconds before.
:earlier {N}
m Go to older text state about {N}
minutes before.
:earlier {N}
h Go to older text state about {N}
hours before.
:earlier {N}
d Go to older text state about {N}
days before.{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
:later {count}
Go to newer text state {count}
times.
:later {N}
s Go to newer text state about {N}
seconds later.
:later {N}
m Go to newer text state about {N}
minutes later.
:later {N}
h Go to newer text state about {N}
hours later.
:later {N}
d Go to newer text state about {N}
days later.{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.CTRL-R
will not get you to all possible text states
while repeating "g-" and "g+" does.au BufWritePre /tmp/* setlocal noundofileVim 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) and ignore it when the file was changed after the undo file was written, to prevent corruption. An undo file is also ignored if its owner differs from the owner of the edited file, except when the owner of the undo file is the current user. Set 'verbose' to get a message about that when opening a file.
:wundo
:rundo
:wundo[!] {file}
Write undo history to {file}
.
When {file}
exists and it does not look like an undo file
(the magic number at the start of the file is wrong), then
this fails, unless the ! was added.
If it exists and does look like an undo file it is
overwritten. If there is no undo-history, nothing will be
written.
Implementation detail: Overwriting happens by first deleting
the existing file and then creating a new file with the same
name. So it is not possible to overwrite an existing undofile
in a write-protected directory.{file}
Read undo history from {file}
.au BufReadPost * call ReadUndo() au BufWritePost * call WriteUndo() func ReadUndo() if filereadable(expand('%:h') .. '/UNDO/' .. expand('%:t')) rundo %:h/UNDO/%:t endif endfunc func WriteUndo() let dirname = expand('%:h') .. '/UNDO' if !isdirectory(dirname) call mkdir(dirname) endif wundo %:h/UNDO/%:t endfuncYou should keep 'undofile' off, otherwise you end up with two undo files for every write.
E822
It cannot be opened, because the file permissions don't allow it.
E823
The magic number at the start of the file doesn't match. This usually
means it is not an undo file.
E824
The version number of the undo file indicates that it's written by a
newer version of Vim. You need that newer version to open it. Don't
write the buffer if you want to keep the undo info in the file.
"File contents changed, cannot use undo info"
The file text differs from when the undo file was written. This means
the undo file cannot be used, it would corrupt the text. This also
happens when 'encoding' differs from when the undo file was written.
E825
The undo file does not contain valid contents and cannot be used.
"Not reading undo file, owner differs"
The undo file is owned by someone else than the owner of the text
file. For safety the undo file is not used.E828
The file to be written cannot be created. Perhaps you do not have
write permissions in the directory.
"Cannot write undo file in any directory in 'undodir'"
None of the directories in 'undodir' can be used.
"Will not overwrite with undo file, cannot read"
A file exists with the name of the undo file to be written, but it
cannot be read. You may want to delete this file or rename it.
"Will not overwrite, this is not an undo file"
A file exists with the name of the undo file to be written, but it
does not start with the right magic number. You may want to delete
this file or rename it.
"Skipping undo file write, nothing to undo"
There is no undo information to be written, nothing has been changed
or 'undolevels' is negative.
E829
An error occurred while writing the undo file. You may want to try
again.clear-undo
When you set 'undolevels' to -1 the undo information is not immediately
cleared, this happens at the next change. To force clearing the undo
information you can use these commands::let old_undolevels = &l:undolevels :setlocal undolevels=-1 :exe "normal a \<BS>\<Esc>" :let &l:undolevels = old_undolevels :unlet old_undolevelsNote use of
&l:undolevels
to explicitly read the local value of 'undolevels'
and the use of :setlocal
to change only the local option (which takes
precedence over the corresponding global option value). Saving the option value
via the use of &undolevels
is unpredictable; it reads either the local value
(if one has been set) or the global value (otherwise). Also, if a local value
has been set, changing the option via :set undolevels
will change both the
global and local values, requiring extra work to save and restore both values.redo-register
If you want to get back more than one part of deleted text, you can use a
special feature of the repeat command ".". It will increase the number of the
register used. So if you first do '"1P', the following "." will result in a
'"2P'. Repeating this will result in all numbered registers being inserted.