Keep your casing with Case-preserving Find and Replace

Leah Tran

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:

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`):

In Quick Replace dialog, Preserve case’ option is represented by an `AB` button, located to right of ‘Use regular expressions` option.

Replace in Files (`Ctrl+Shift+H`):

In Replace in Files window, checkbox for ‘Preserve case’ option is listed right below `Use regular expressions`.

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.

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

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.

3 comments

Discussion is closed. Login to edit/delete existing comments.

  • Mystery Man 4

    I’m glad to see this feature made its way into the mainstream Visual Studio. It was part of VSCode before.

    Here is another feature request: In future blog posts, instead of animated GIFs, please use proper video formats. They are smaller. Plus, the browser adds proper controls like a seek bar.

  • Ali Aslani 4

    Hello to all.
    This new feature is really very good and useful.
    I hope it reaches the original version of Visual Studio as soon as possible.

  • Dwayne Robinson 0

    Nice. I had to do two search&replaces with case sensitivity before for PascalCase/camelCase.

    Another useful option would be skipping over “_” underscores, because some codebases like Chromium are a large inconsistent mess of both snake_case and camelCase (e.g. ConvActivation(), kConvActivation, convActivation, but also conv_activation 🙃). Currently I need three search&replaces to substitute them all, but at least that’s now reduced (with this feature 👍) to just two 😊.

Feedback usabilla icon