Freigeben über


Undo Quick Replace and Replace in Files

Keyboard:  CTRL + Z
Menu:  Edit -> Undo
Command:  Edit.Undo
Versions:  2008,2010
Published:  11/25/2010
Code:  vstipFind0020

 

When using Find and Replace people often wonder under what conditions you can Undo the changes.  Since doing a "Find Next" and "Replace" operation is very straightforward and easy to Undo, I'm going to focus on how to Undo the "Replace All" operations.  Here is a summary of the conditions that allow Undo to happen:

 

Quick Replace (CTRL + H)

If I do a Quick Replace on "Current Project" or "Entire Solution":

image

 

 

Then do a "Replace All" By default it will open closed documents and mark them as dirty (put an asterisk in the file name tab) so you can Undo the changes:

image

 

 

When you Undo (CTRL + Z) here it will back out all the changes it made.  In this case it will Undo all eleven changes:

image

 

 

For those wondering, this is what the entry looks like in the Undo stack:

image

 

 

 

Replace in Files (CTRL + SHIFT + H)

If I do a Replace in Files on "Current Project", "Entire Solution", or "Visual C++ Include Directories":

image

 

 

Notice there is an option to "Keep modified files open after Replace All".  If I do not select that option and click "Replace All" then I will get this message regardless if the files where changes would be made are open or not:

image

 

 

Checking the "Replace All will open all files with changes for editing" will make it possible to Undo the changes made:

image

 

 

And here is the entry in the Undo Stack:

image

 

 

Finally

Hopefully this helps as you explore the inner workings of Visual Studio and how the various tools work.