Keyboard: CTRL + H
Menu: Edit -> Find and Replace -> Quick Replace
Command: Edit.Replace
Versions: 2008,2010
Published: 6/15/2010
Code: vstipFind0008
Folks, I need some feedback on this tip. It basically is a cut and paste of the "Quick Find" tip and highlights the inner turmoil of this blog. Should I try to make each tip independent so that when you read it there is no other tip you need OR should I refer to other tips to avoid copying information over again? Let me know your thoughts.
We previously looked at Quick Find and now we will look at Quick Replace. Note that they are pretty much exactly the same except for the replace operation itself. Press CTRL + H to bring up the Quick Replace tool window:
Okay, so notice this is a tool window so right away it can be docked like any other tool window pretty much anywhere you want. Notice the Quick Replace drop down let's you choose what type of replace you want to do:
For this discussion we will only focus on the Quick Find choice but each of these items comes with its own set of options. The "Find what" area is used to determine what you want to find:
You can type what to look for in the dropdown combo box or you can choose from the list of previous searches:
Don't worry about that extra button to the right of the dropdown combo box-we will get to that later :)
The "Replace with" area functions exactly the same way but it takes the text that you want to be used to replace the "Find what" text with:
Next is the "Look in" area. It's used to determine the scope of your search:
Most of the options are pretty self explanatory. There is one key thing to know: "Current Project" and "Entire Solution" will search files whether they are open or closed.
The "Find options" area is where the fun really happens:
Here is a run-down of these options:
Match case - Makes your search case-specific. Searching for elocal would show "elocal" but not "eLocal" or any other variant.
Match whole word - by default the search is a "contains" operation and will find anywhere the word exists. For example, searching for "elocal" will find "elocal" and "elocalstuff", etc.
Search up - Ordinarily, the search will start from the current cursor location and search down in the current document. You can use this option to search up from the current cursor location instead.
Use -
This is a LOT more interesting and requires a bit of explanation. When you select this you get to choose between "Regular expressions" and "Wildcards":
When you use this option it will automatically enable the Expression Builder button to the right of the "Find what" combo box:
Regular Expressions - Let's you use regular expressions in your search. If you are not familiar with regular expressions you can check out my series on them here: http://blogs.msdn.com/b/zainnab/archive/2008/03/11/regular-expression-webcast-series.aspx. Here is what the Expression Builder button will give you when you use it:
Wildcards - This isn't as advanced as regular expressions but is more familiar to most people. It allows you to use special characters to represent one or more letters. Go here for more information on wildcard searches: http://msdn.microsoft.com/en-us/library/afy96z92.aspx. This is what the Expression Builder button will give you with this item selected:
Finally, we have the three buttons at the bottom of the Quick Replace tool window:
Find Next - Will keep going to the next instance of the search term you are looking for until it reaches your original starting point.
Replace - will replace the next instance of "Find what" using the text in "Replace with".
Replace All - will replace all instances of "Find what" using the text in "Replace with". This produces a dialog that shows how many replacements were made:
Make sure to pay attention to this value as it may be higher (or lower) than expected and may require further investigation.
That's it! You now know how to do a Quick Replace! :)