Keep your casing with Case-preserving Find and Replace
The Visual Studio search experience is getting a new feature that allows users to find and replace text without having to worry about different casings. For example, a method parameter `catalogItemId` and object property `CatalogItemId` have the same name but different capitalization but should both be replaced by something like ‘productId’ with their respective casings.
The feature has been requested by users who were looking for an easy way to find and replace text without having to worry about different casings in various forums, including Stack Overflow and Developer Community Case-Preserving Search & Replace Across Multiple Files. We’re excited to finally announce that Case-Preserving Find and Replace is available as of 17.8 Preview 1!
We’re committed to maintaining and improving the search experience in Visual Studio. Over the years, we’ve continued to enhance and update search. You can learn more about these changes by visiting the following links:
- Search – Visual Studio Blog (microsoft.com)
- Find – Visual Studio Blog (microsoft.com)
- Find in Files – Visual Studio Blog (microsoft.com)
How to use it
When you do a Replace, you can now preserve the original casing of each match in your code. Toggle case preservation in the Replace window with `Alt+V` or by clicking on the Preserve case option.
Quick Replace (`Ctrl+H`):
Replace in Files (`Ctrl+Shift+H`):
To get Pascal case and 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.
– 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”.
Try it out and let us know what you think.
As you wait for it to come to the stable release, you can try out the case preserving replace experience in 17.8 Preview 1 and on. Feel free to contribute to the existing ticket on Developer Community and report any issues you find on Developer Community.