2

Whenever I do undo and redo in vim, I saw this output, the #number changes.. but what is it ? Where to see the #number .. ?

Also, I find it hard to know what. I have accidentally changed or undo sometime. Hence I have to keep undo and redo, until I am sure what is the correct status before I dare to write the buffer, least I saved the file in unwanted "undo / redo".

I find this is very hard in vim usage, especially sometime there are multiple accidental undo or redo.. (especially when my brain is too full to the brim, that I can't think properly), if only there is way to make undo or redo ed lines/text in red color (or anything that attracts my attention) for a moment.. so I know what is the difference between the pressing of "undo / redo".

1 change; after #12 12:30:02 enter image description here

2 Answers 2

2

Vim keeps track of the operations we perform as a list of changes. From :h :undolist:

:undol[ist]     List the leafs in the tree of changes.  Example:
               number changes  when               saved ~
                   88      88  2010/01/04 14:25:53
                  108     107  08/07 12:47:51
                  136      46  13:33:01             7
                  166     164  3 seconds ago

When we undo or redo (see :h u and :h CTRL-R) a change, it displays which change it is un/re-doing. For example, if it shows "1 change; after #12 12:30:02," that means you have made 12 changes and pressed u and then <C-R>. "after" means the buffer currently holds the content it'd hold "after" you committed the 12th change.


Remarks:

you have made 12 changes and pressed u and then <C-R>

There are countless other scenarios for this message to pop up. You could've made 13 changes and pressed u twice and <C-R> once; or you could've made 14 changes and pressed u thrice and <C-R> twice. I could write it more generally with arithmetic notations, but that would needlessly complicate a simple explanation.

4
  • I have tried to do undo redo to try out with :undol, but i can't see how this help op in anything. Does this "1 change; after #12 12:30:02" help you by providing you any useful info at all ? Apart from knowing oh i changed something.. or i have deleted some lines..
    – andrew_ysk
    Sep 24, 2022 at 14:50
  • @andrew_ysk, it tells you where in the "tree of changes" you are. Rather than me explaining how it works in workflow, you should try the undotree plugin Vivian suggested in the other answer. That plugin harnesses the undo tree feature of vim in a visual manner. It'll be easier to understand. Then you can understand how :undol and the undo/redo output could help the user.
    – 3N4N
    Sep 24, 2022 at 14:56
  • @andrew_ysk, but for your original question ("but what is it ? Where to see the #number .. ?"), what I posted is the answer. Granted, you also asked for a diffing tool for the change, but I don't have any suggestion on that. I can tell what changed just by repeating u<C-R> a couple of times. It kinda flashes the diff, which, if I do it enough times, burns the difference in my eyes.
    – 3N4N
    Sep 24, 2022 at 15:00
  • Thanks. I have installed undotree and looking into it currently. Thanks for explaining me.
    – andrew_ysk
    Sep 24, 2022 at 15:19
0

May be the following plugin: undotree could help you.

It shows you all the states of document with:

  • The state index (e.g.: #12)
  • The time delta
  • A flag S to determines if it corresponds to a state that has been saved on disk.

The undo or redo should bring you at the corresponding place of the document helping to catch what was the change.

The following receipt gives you a Diff command that help you comparing your buffer with the status of the file on disk.

I found that one quite useful.

4
  • 1
    You are right. But the use case is common and maybe deserve an answer too? Sep 24, 2022 at 12:52
  • "@Vivian De Smedth" Thanks for suggesting. I have installed it. Am learning how to use it to my benefit when i am uncertain what have being modified when undo/ redo ; before i do :w.
    – andrew_ysk
    Sep 24, 2022 at 15:40
  • By The Way, After i do a :wq , all the undo/redo (changes) is no longer available right ? I read all those changes history are store in RAM. Hence when i close the buffer, all those are gone, unless i do undo-persistent thing.. which is not needed in my case.
    – andrew_ysk
    Sep 24, 2022 at 15:43
  • This depend on the way you configure Vim and in particular of the options set undofile (and its sister set undodir). Sep 24, 2022 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.