Share via


Replace in Files, Find and Replace Window

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.

Note

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 Visual Studio 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

  1. On the Edit menu, expand Find and Replace.

  2. 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.

Find what

These controls allow you to specify the string or expression that will be matched.

  • Find what
    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.

    • [regular expression]
      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.

  • Expression Builder
    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.

  • Find Next
    Click this button to find the next instance of the Find what string within the search scope chosen in Look in.

Replace With

These controls allow you to specify what will be inserted in the place of the matched string or expression.

  • Replace with
    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.

  • Expression Builder
    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.

  • Replace
    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.

  • Replace all
    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.

    Warning

    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.

  • Skip File
    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.

Look in

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.

Note

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.

  • Look in
    Select a predefined search scope from this list, or use the Choose Search Folders dialog box to enter your own set of directories.

    • Current Document
      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.

    • Entire Solution
      Searches all files in the active solution.

    • Current Project
      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.

  • Browse (...)
    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.

  • Include sub-folders
    Specifies that subfolders of the Look in folder will be searched.

Find options

You can expand or collapse the Find options section. The following options can be selected or cleared:

  • Match case
    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."

  • Use
    Indicates how to interpret special characters entered in the Find what or Replace with text boxes. The options include:

    Option

    Description

    Wildcards

    Special characters such as asterisks (*) and question marks (?) represent one or more characters. For a list, see Wildcards (Visual Studio).

    Regular Expressions

    Special notations define patterns of text to match. For a list, see Regular Expressions (Visual Studio).

  • Look at these file types
    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 (;).

Result options

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.

    Warning

    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.

Toolbar

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.

Drop-down

View menu

Find (left drop-down)

Quick Find

Find in Files

Find Symbol

Replace (right drop-down)

Quick Replace

Replace in Files

See Also

Tasks

How to: Search Interactively

How to: Search Using Results Lists

How to: Search a Document Incrementally

Reference

Find in Files, Find and Replace Window

Quick Replace, Find and Replace Window

Visual Studio Commands with Arguments

Other Resources

Find and Replace Window

Finding and Replacing