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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With