6
1
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:
- Undo until the deleted text appears again
- Yank the text into some register
- Redo the undo history until I'm at the "current" version again
- 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.
In Feature request: Search through undo history, the author of the Undo-tree plugin suggested a simple algorithm that could be used to implement this functionality in Vim:
– Rory O'Kane – 2015-02-25T17:16:08.280loop until undo is not available { search "the string"; undo one step; }
. Undo status is available through Vim’sundotree()
function.See http://vi.stackexchange.com/q/2220/1060
– Kyle Strand – 2015-02-26T20:20:46.5771I 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
andgit 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 togit log -p
by just using the search inless
, but this can't be done in Gundo. – Steven Lu – 2013-07-15T20:28:11.160Ah, correction: -S for git pickaxe search for string, -G for git pickaxe search for regex. Quite powerful. – Steven Lu – 2013-07-16T00:01:44.517