Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a "weird" usage pattern in vim that I often use - or have to use, depending on how you view it.

What normally happens is this: I enter some text, do some editing, then remove a bit of text again. Some time in the future, I figure that this deleted bit of text would again be useful, so the following happens:

  1. Undo until the deleted text appears again
  2. Yank the text into some register
  3. Redo the undo history until I'm at the "current" version again
  4. Paste the yanked text

What I'm wondering is this: Is there a way to search for something in the undo history of a file, so I won't have to undo dozens (or hundreds) of undoes to get to the right version?

Note that I'm explicitly not looking for an "external" VCS like Git or Subversion - I'm trying to search for changes before even having to save a file to disk.

share|improve this question
1  
I believe there is a "market" for this: to accelerate the workflow of finding a past change by automated culled search rather than manual linear search: c.f. git log -p and git log -p -S 'regex_for_change'. I'm not aware of any vim feature (or Gundo feature) that lets you specifically target a part of the diffs. For example, it is very easy to add power to git log -p by just using the search in less, but this can't be done in Gundo. –  Steven Lu Jul 15 '13 at 20:28
    
Ah, correction: -S for git pickaxe search for string, -G for git pickaxe search for regex. Quite powerful. –  Steven Lu Jul 16 '13 at 0:01

2 Answers 2

up vote 1 down vote accepted

It looks like what you want to do is the exact use case for Gundo.

share|improve this answer
1  
The perils of multitasking: you start to type an answer, then you have to deal with an "emergency", you come back and finish your answer, hit the button and notice that there's already a similar answer. With a beautiful screenshot. –  romainl Apr 25 '12 at 14:34
    
Gundo is extremely useful, but is there an easy way to search the various versions of the file shown in the undo tree? –  Kyle Strand Jan 20 at 21:11
    
@KyleStrand, I don't think you can be more granular than Gundo's diff feature. –  romainl Jan 20 at 21:19
    
I'm not really asking for granularity, I'm asking for search capabilities. Specifically, I'd like the ability to submit a search query that would search through all of the diffs shown by Gundo and display something like a list of all the versions of the file that have that search pattern in their diff. Superficially, this seems like what the original question here is asking, but since your answer doesn't really answer mine and has been "accepted" anyway, I was thinking I should just write a new question. –  Kyle Strand Jan 20 at 21:24
    
No, what you should do is follow the link in my answer and look for what you want in the documentation. AFAIK it doesn't do what you want, though. –  romainl Jan 20 at 21:32

Have you tried :history? This shows the command history (edited and emphasized after comment) registers that are currently available. See :help history in Vim for more information.


For the history buffers regarding input, see :h undo-redo (specifically the :h :undolist section).

Also see How is Vim's undo tree used? (SO) and Using undo branches (Vim wiki).

share|improve this answer
    
That's the command history, not the history of the file. –  Dave Vogt Apr 25 '12 at 13:17
    
@DaveVogt: So it is, updated my answer with the correct help section for your request. –  Daniel Andersson Apr 25 '12 at 13:21
    
Thanks for the links. The second one has an answer pointing to bitbucket.org/sjl/gundo.vim which is already pretty close. –  Dave Vogt Apr 25 '12 at 13:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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