Expressions of case

You surely already know you can search and replace inside of a given file. You hopefully also know you can search and replace in any folder of the project, invoking the Find in Path or Replace in path dialogs. That’s Cmd-Shift-F and Cmd-Shift-R for you (or, with Ctrl instead of Cmd if you don’t use a Mac, or use the old school Mac OS keymap like yours truly).

Now, you have a bunch of options for searching, like matching the case, using regular expressions, and so on. You can’t really change the capture groups for the replace part though, can you?

You would normally have something like this:

As you can see in this very much contrived example, simply using this search and replace setup would not work as it would break camel casing.

To help us get what we really want, we have some very little known allies, in the form of some case modifiers to use for the replace clause:

\l makes the next character lowercase

\u makes the next character uppercase

\L makes the next characters lowercase, until the matching /E

\U makes the next characters uppercase, until the matching /E

This is enough to cover most situations, such as our example:

Remember, if you have a refactoring available to rename a symbol, that’s usually the wise way to go — unless you’re trying to rename a bunch of internal symbols that all look kinda the same and you’re super sure won’t break other stuff. Or if you can’t use refactorings. In those cases, this is going to save you a lot of time!