Replace in Files allows you to search the code of a specified set of files for a string or expression, and change some or all of the matches found. The matches found and actions taken are listed in the Find Results window selected in Result options.
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Working with Settings.
You can use any of the following methods to display Replace in Files in the Find and Replace window.
To display Replace in Files
On the Edit menu, expand Find and Replace.
Choose Replace in Files.
— or —
If the Find and Replace window is already open, on the toolbar, click the triangular View button on the right drop-down list and then chose Replace in Files.
These controls allow you to specify the string or expression that will be matched.
Reuse one of the last 20 search strings by selecting it from this drop-down list, or type a new text string or expression to find.
[string with wildcards]
If you want to use wildcards such as asterisks (*) and question marks (?) in your search string, select the Use check box under Find options and choose Wildcards.
To cause the search engine to interpret your search string as a regular expression, select the Use check box under Find options and choose Regular expressions.
This triangular button next to the Find what field becomes available when the Use check box is selected in Find options. Click this button to display a list of wildcards or regular expressions, depending upon the Use option selected. Choosing any item from this list adds it to the Find what string.
Click this button to find the next instance of the Find what string within the search scope chosen in Look in.
These controls allow you to specify what will be inserted in the place of the matched string or expression.
To replace instances of the Find what string with another string, enter the replacement string in this field. To delete instances of the Find what string, leave this field blank. Select the drop-down list to display the last 20 items entered. To include regular expressions in the Replace with string, click the Use check box under Find options and select the Regular Expressions option.
This triangular button next to the Replace with field becomes available when the Use check box is selected in Find options. Click this button to display a list of regular expressions, depending upon the Use option selected. Choosing any item from this list adds it to the Replace with string.
Choose this button to replace the current instance of the Find what string with the Replace with string, and find the next instance within the Look in scope.
Choose this button to replace all instances of the Find what string with the Replace with string, in all files within the Look in scope.
Make sure that the Look in scope is set to include only those files that you want to modify.
A reminder is displayed that includes a Keep modified files open after Replace All option. To retain the Undo option, you must select this option. Undo is only available in files that remain open for editing after they are modified.
Becomes available when the Look in list includes multiple files. Choose this button if you do not want to search or modify the current file. The search will continue in the next file on the Look in list.
The option chosen from the Look in drop-down list determines whether Replace in Files searches only in currently active files or searches all files stored within certain folders. Select a search scope from the list, type a folder path, or click the Browse (...) button to display the Choose Search Folders Dialog Box and choose a set of folders to search. You can also type a path directly into the Look in box.
If the Look in option selected causes you to search a file that you have checked out from source code control, only the version of that file which has been downloaded to your local machine is searched.
Select a predefined search scope from this list, or use the Choose Search Folders dialog box to enter your own set of directories.
This option is available when a document is open in an editor. Searches only the active document for the Find what string.
All Open Documents
Searches all files currently opened for editing.
Searches all files in the active solution.
Searches all files in the active project.
Visual C++ Include Directories
This option becomes available while editing Visual C++ projects. Searches all files in the Include Directories.
Choose this button to display the Choose Search Folders Dialog Box, where you can assemble, edit, save, and select named sets of directories to enter in the Look in field.
Specifies that subfolders of the Look in folder will be searched.
You can expand or collapse the Find options section. The following options can be selected or cleared:
When selected, the Find Results windows will only display instances of the Find what string that are matched both by content and by case. For example, a search for "MyObject" with Match case selected will return "MyObject" but not "myobject" or "MYOBJECT."
Match whole word
When selected, the Find Results windows will only display instances of the Find what string that are matched in complete words. For example, a search for "MyObject" will return "MyObject" but not "CMyObject" or "MyObjectC."
Indicates how to interpret special characters entered in the Find what or Replace with text boxes. The options include:
Special characters such as asterisks (*) and question marks (?) represent one or more characters. For a list, see Wildcards (Visual Studio).
This list indicates the types of files to search through in the Look in directories. If this field is left blank, all of the files in the Look in directories will be searched.
Select any item in the list to enter a preconfigured search string that will find files of those particular types.
To find a type of file not available from the drop-down list, enter an asterisk (*) wildcard for the file name, followed by a period (.) and the desired file extension. To find more than one file type, enter multiple file extensions separated by a semicolon (;).
You can expand or collapse the Result options section. The following options can be selected or cleared:
Find Results 1 window
When selected, the results of the current search will replace the content of the Find Results 1 window. This window opens automatically to display your search results. To open this window manually, select Other Windows from the View menu and choose Find Results 1.
Find Results 2 window
When selected, the results of the current search will replace the content of the Find Results 2 window. This window opens automatically to display your search results. To open this window manually, select Other Windows from the View menu and choose Find Results 2.
Keep modified files open after Replace All
When selected, leaves open all files in which replacements have been made, so you can undo or save the changes. Memory constraints might limit the number of files that can remain open after a replace operation.
You can use Undo only on files that remain open for editing. If this option is not selected, files that were not already open for editing will remain closed, and no Undo option will be available in those files.
A toolbar, with two drop-downs, appears at the top of the Find and Replace window. These drop-downs allow you to choose the type of search or replace you intend to perform and changes the options displayed in the window to match.