Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redo all undone changes

Tags:

vim

undo-redo

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.

like image 920
Zoey Hewll Avatar asked Feb 02 '26 03:02

Zoey Hewll


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.

like image 110
Wilson Wong Avatar answered Feb 03 '26 22:02

Wilson Wong


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.

like image 37
Ingo Karkat Avatar answered Feb 03 '26 21:02

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!