Reputation: 5385
Similar to this question, is there a command to redo all undone changes in vim? Currently all I know is 1000<C-R>
or similar, to just redo a large number of changes, but it feels cumbersome and rather arbitrary.
Upvotes: 3
Views: 1430
Reputation: 172520
Vim has undo branches, not just a linear undo sequence; this is important to bear in mind. To go to the latest text state, you can use 9999g+
(the 9999
is an arbitrary high number). Alternatively, you can use :later 1d
.
Upvotes: 3
Reputation: 406
Try :exec 'undo' undotree()['seq_last']
This will redo every change up to the latest change.
If you want to map it to something like ctrl+shift+R. Place this in your vimrc file:
nnoremap <C-S-R> :exec 'undo' undotree()['seq_last']<CR>
Explanation
undo {N}
jumps to the nth change in the undo tree.
undotree()
is a function that returns a dictionary with the state of the undo tree.
undotree()['seq_last']
looks up the key seq_last
in the dictionary.
From :help undotree
we see that the value associated with seq_last
is:
The highest undo sequence number used.
:exec
evaluates the string from our expression.
Let's say for example, undotree()['seq_last']
returns 42
.
The expression in this example would be undo 42
which brings us to our latest change, the 42nd one.
Upvotes: 8