Condividi tramite


Using Quick Replace

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:

image

 

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:

image

 

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:

clip_image006

 

You can type what to look for in the dropdown combo box or you can choose from the list of previous searches:

clip_image008

 

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:

image

 

Next is the "Look in" area.  It's used to determine the scope of your search: 

image

 

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:

clip_image012

 

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":

clip_image014

 

When you use this option it will automatically enable the Expression Builder button to the right of the "Find what" combo box:

clip_image016

 

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:  https://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:

clip_image018

 

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:  https://msdn.microsoft.com/en-us/library/afy96z92.aspx.  This is what the Expression Builder button will give you with this item selected:

clip_image020

 

Finally, we have the three buttons at the bottom of the Quick Replace tool window:

image

 

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:

image

 

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! :)

Comments

  • Anonymous
    June 15, 2010
    IMO you should do things like "Find" and "Replace" in one post. Having two this nearly identical posts might get you banned from Google ;-)

  • Anonymous
    June 15, 2010
    Nice.  But if I did them in one post it would mean the posts would be pretty long.  So longer posts > multiple posts?

  • Anonymous
    June 15, 2010
    Like Jannik says, combining them together makes sense if there's almost complete overlap. When there's less overlap, I think it makes sense to duplicate small sections instead of making people who found a particular tip read several others and piece the info together. Depends how much overlap there is, though. Also, where there is overlap it's great to have it signposted so that people who read every tip know they can stop reading or skip marked sections. That keeps regular readers happy while not making it a pain for people who came to read a particular tip (e.g. via a web search).

  • Anonymous
    June 15, 2010
    I'm definitely in favor of combining them. Especially when they're exactly the same like this - I hope you can consider your readers smart enough to understand side-by-side images, or Find/Replace in the text, or some way of presenting them together. That way we get more new tips faster. But then I'm cranky after a long day at work and several weeks of tips that are not news to me. But I'm sure there's another "aha, that's awesome!" coming soon, so Go Zain Go!

  • Anonymous
    June 15, 2010
    Good feedback thanks folks :) I'll combine them when there is considerable overlap and copy small sections where there isn't.  That seems to achieve the goal of each tip standing on it's own. Z

  • Anonymous
    June 15, 2010
    I say combine them, but for posts that are similar to this specific case, just note the different keyboard shortcuts to use.  That way, if I'm searching the blog by keyboard shortcut, I'd find the right post.