Tim Chase wrote:
I think given those conditions (autowrite and nohidden), there seems to be no such way from my experimenting. However, if you switch to using hidden instead of nohidden, you can do

    :argdo u

which will undo the last action in each argument.

I've been casually looking for such a feature, but so far I've come up a little short. After a multi-file search-and-replace, I'd like to be able to undo the replace across the files. The `:argdo u` command almost does what I want, but I can't think how to restrict the undo operation to changes made only by the replace operation. For example, suppose I create two files and edit them together:

    echo "first file" > first.txt
    echo "second file" > second.txt
    gvim first.txt second.txt

Suppose in first.txt I edit `first` to become `1st` using Vim editing commands:

    cw1st<Escape>

Now I perform a search-and-replace to change `second` to `2nd`:

    :argdo %s/second/2nd/ge


Now I try to undo my most recent replace operation:

    :argdo u

I'd like this to undo only the change(s) made by the s/// command, but it also changes `1st` back to `first`. Since the `u` is performed indiscriminately in all arguments regardless of whether the s/// command made changes there, I can't blindly use the undo trick to reverse an arbitrary replace operation.

I've tried saving all buffers before doing the replace operation, but `:argdo u` undoes past the save (which generally pleases me greatly, but is unfortunate in this case :-)).

I searched for "replace undo" in Vim's plugins and tips, but came up empty. Does anyone have a pointer to a plugin or other resource to allow blind undoing of multi-file replace operations?

Thanks,
Michael Henry

Reply via email to