Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Replace in Files enables 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.
Important
If you use Visual Studio 2019 version 16.6 or earlier, the Find and Replace dialog box might not look as it appears here. Switch to the Visual Studio 2017 version of this page to get descriptions that match what you see on your screen.
You can use any of the following methods to display Replace in Files in the Find and Replace window. You can also use Ctrl+Shift+H.
To display Replace in Files
Press Ctrl+Q and enter replace in the search box at the top of the screen. Double-click Replace in files in the list of results.
— or —
On the Edit menu, select Find and Replace and then select Replace in Files.
— or —
If the Find and Replace window is already open, select the Replace in Files tab.
Note
The Find and Replace tool doesn't search folders that have the Hidden
or System
attribute.
The Replace in Files options are almost identical to the options in the Find in Files dialog. Depending on the version of Visual Studio that you use, there might be more replace options available in the dialog, as described in the following sections.
Replace box
To replace instances of the string in the Find box with another string, enter the replacement string in the Replace box. To delete instances of the string in the Find box, leave the Replace box blank. Select the dropdown arrow in the Find box to display the strings that you most recently searched for. Select the User regular expressions checkbox and then select the adjacent Replace 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.
Preserve case
When you perform a replace operation, you can preserve the original casing of each match in your code. You can turn case preservation on and off by using the Preserve case option (Alt+V). This option is available in Visual Studio 2022 version 17.8 or later.
To preserve Pascal case or camel case, your replace string must also be in Pascal case or camel case. Case is also preserved in text that contains hyphens or underscores.
Here are some examples:
Replacing "begin" with "end" will turn "Begin" into "End" and "BEGIN" into "END".
Replacing "onetwothree" with "fourFiveSix" will turn "onetwothree" into "fourfivesix", "oneTwoThree" into "fourFiveSix", and "OneTwoThree" into "FourFiveSix".
Keep modified files open after Replace All
When you select Keep modified files open after Replace All, all files in which replacements have been made are left open, 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 Keep modified files open after Replace All isn't selected, files that weren't already open for editing will remain closed, and no Undo option will be available in those files.
Note
Starting with Visual Studio 2022, to optimize search performance, partial results, such as results from pre-indexed files, are shown before final results are available. However, when you perform replace operations, this performance benefit doesn't apply because replace operations are started only after full search results are returned.