Replace in Files

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

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.

Screenshot of the Find and Replace dialog box in Visual Studio 2017, with the Replace in Files tab open.

You can use any of the following methods to display Replace in Files in the Find and Replace window, or use Ctrl+Shift+H.

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, choose Replace in Files.

Note

The Find and Replace tool does not search directories with the Hidden or System attribute.

The Replace in Files options are identical to those in the Find in Files dialog, with two exceptions: There are additional replace action buttons at the bottom of the dialog. And, there are the following replace options available in the dialog.

Replace With

To replace instances of the string in the Find what box with another string, enter the replacement string in the Replace With box. To delete instances of the string in the Find what box, leave this field blank. Open the list to display the 20 strings for which you searched most recently. Choose the adjacent Expression Builder button if you want to use one or more regular expressions in your replacement string. For more information, see Use regular expressions in Visual Studio.

Display file names only

When this check box is selected, the Find Results windows list the full names and paths for all files that contain the search string. However, the results don't include the line of code where the string appears. This check box is available for Find in Files only.

Keep modified files open after Replace All

When selected, this option 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.

Caution

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.

See also