Redo all undone changes

Viewed 1134

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.

2 Answers

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.

Related