Hi, On 5/23/07, Michael Henry <[EMAIL PROTECTED]> wrote:
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?
You can try using the gReplace Vim plugin: http://vim.sourceforge.net/scripts/script.php?script_id=1813 Even though this plugin doesn't provide the "undo" operation across multiple buffers, it allows you to interactively change a pattern across multiple buffers/files and you can abandon the changes before the buffers are updated with the change. For example, to replace a pattern across multiple buffers, you can do the following: 1. Execute the ":Gbuffersearch <pattern>" command. This will open a buffer with all the lines containing <pattern> in all the open buffers. 2. You can edit this buffer using the usual Vim editing commands. 3. Now you can execute the ":Greplace" command to incorporate all the changes made in the replace buffer back to the corresponding buffers. 4. To abandon making the changes, you can just close the replace buffer. - Yegappan
