Quick Refactor: Keep Casing in VSCode Search + Replace

February 25, 2021 • 2 min read

Presentation image

THE PROBLEM

We have a pet object, whose value under the key of name we are changing. We are saving a reference to the old value that the key name pointed to for logging purposes.

Presentation image

Now we realize that we’d like to rename the key name to alias. A refactoring is in order. So we pull up the find and replace feature by pressing ctrl/cmd + f.

Presentation image

But oops! as they key name is also used in camelCase as part of other variables names newPetName and oldPetName , we get a casing mismatch after replacing. newPetalias and oldPetalias don’t look so good…

Presentation image

A SOLUTION

We are going to undo this change and repeat it using the preserve case option on the find and replace feature by pressing the AB button.

Presentation image

Now we’ve saved time refactoring and our pets are happy with their aliases!

Presentation image

WDYT about this post? I read you here:

Get notified of new blog posts?

RSS FeedGet an Email

RSS is the correct choice, btw.