Revert all undos

28 views
Skip to first unread message

BPJ

unread,
Oct 23, 2024, 9:53:37 AM10/23/24
to vim_use
Probably a FAQ but I could not find an answer online.

Is there a single mapping or command for reverting/redoing all undos, or alternatively how could one be created, e.g. is there a way to get the number of extant undos?[1]

The use case is that because of my disability I have remapped all `<C-...>` and `<S-...>` mappings I use frequently to use a sequence of two/three keys instead of two/three simultaneous keys (Typically `<F-...>...` with one `<F-...>` for each of `<C-...>` and `<S-...>`) but because of the same disability hitting the same two-key sequence over and over is also difficult.[2]

TIA,

/bpj

[1]: Obviously I can do `:w` before the undos and then `:e` but I keep forgetting the `:w`! :-)

[2]: Sometimes I can use the regular modifier key command, holding down CTRL and pressing the other key repeatedly with the other hand, but in Termux on my tablet or phone those are also two-key sequences so I'm toast anyway! (Of course I have my remappings in Termux too...)

Tim Chase

unread,
Oct 23, 2024, 10:37:52 AM10/23/24
to vim...@googlegroups.com
On 2024-10-23 15:53, BPJ wrote:
> Is there a single mapping or command for reverting/redoing all undos, or
> alternatively how could one be created, e.g. is there a way to get the
> number of extant undos?[1]
[snip]
> [1]: Obviously I can do `:w` before the undos and then `:e` but I keep
> forgetting the `:w`! :-)

While this works, note that it also loses those undo points and any
jumps (`:help jumplist`) or marks you've set in the file.

Often, if you're bulk-undoing, that's fine. But it's worth being aware
that :e overwrites some state you might care about.


Other possibilities:

- you should be able to use a count with undo like

15u

and it doesn't complain about you requesting more undo than exists, so
you can do ridiculous counts like

99999u

to undo lots of changes

- you can use :earlier and :later to navigate based the undo tree based
on time rather than undo counts, so you can do things like

:earlier 15m
:earlier 2h
:earlier 1f

(and in typing that up, I learned about the "f" suffix for
file-write-counts...nice!)

-tim





BPJ

unread,
Oct 24, 2024, 8:06:27 AM10/24/24
to vim_use
Den ons 23 okt. 2024 16:38Tim Chase <v...@tim.thechases.com> skrev:
On 2024-10-23 15:53, BPJ wrote:
> Is there a single mapping or command for reverting/redoing all undos, or
> alternatively how could one be created, e.g. is there a way to get the
> number of extant undos?[1]
[snip]
> [1]: Obviously I can do `:w` before the undos and then `:e` but I keep
> forgetting the `:w`! :-)

While this works, note that it also loses those undo points and any
jumps (`:help jumplist`) or marks you've set in the file.

Often, if you're bulk-undoing, that's fine.  But it's worth being aware
that :e overwrites some state you might care about.

Oh, good to learn that. I think I have noticed marks disappearing, definitely undos. Sometimes when writing part of a file to a file with another format/extension — typically in order to quote some code snippet in a Markdown file — I'll get the original file set to the wrong syntax/format — probably because my syntax/format hacks in `~/.vim/after/` are shitty but anyway! — and `:e` is then the easiest way to restore things.



Other possibilities:

- you should be able to use a count with undo like

  15u

  and it doesn't complain about you requesting more undo than exists, so
  you can do ridiculous counts like

  99999u

  to undo lots of changes

Very good to know as I have been worrying about not knowing how many changes I need to undo.



- you can use :earlier and :later to navigate based the undo tree based
  on time rather than undo counts, so you can do things like

  :earlier 15m
  :earlier 2h
  :earlier 1f

Didn't know about these!


(and in typing that up, I learned about the "f" suffix for
file-write-counts...nice!)

Very nice and very useful, especially if `:w` doesn't have the same side effects as :e mentioned above!

Thanks a lot!

/bpj

Tim Chase

unread,
Oct 24, 2024, 8:34:19 AM10/24/24
to vim...@googlegroups.com
On 2024-10-24 14:06, BPJ wrote:
>> Other possibilities:
>> - you should be able to use a count with undo like
>> 15u
>> and it doesn't complain about you requesting more undo than exists, so
>> you can do ridiculous counts like
>> 99999u
>> to undo lots of changes
>
> Very good to know as I have been worrying about not knowing how many
> changes I need to undo.

There's an internal limit that you can tweak:

:help 'undolevels'

so you can adjust that up/down as you see fit. You just have to do it
before you make that many changes (so a good candidate for your vimrc)

>> - you can use :earlier and :later to navigate based the undo tree based
>> on time rather than undo counts, so you can do things like
>> :earlier 15m
>> :earlier 2h
>> :earlier 1f
>
> Didn't know about these!

I don't use them often because my internal/mental clock doesn't sync up
with my editing, but if they help you out, they're good to have in your
tool-belt.

>> (and in typing that up, I learned about the "f" suffix for
>> file-write-counts...nice!)
>
> Very nice and very useful, especially if `:w` doesn't have the same side
> effects as :e mentioned above!

Correct, the :e reloads the buffer (similar to passing a range through
an external filter with `:help :range!` which impacts that range),
losing the marks, jump-points, etc. in that range. But :w shouldn't
impact those.

-tim





Reply all
Reply to author
Forward
0 new messages