VSCode Tips: Effortless Word Replacement Tool for Efficiency

Harnessing VSCode's Word Mass Replacement Feature

Elly Mar Project Screenshot
Elly Mar Project Screenshot

I currently need to rename a variable throughout my entire project to make it more descriptive and accurate. I confess, I'm not the best at naming variables initially.

source code snippet
Source Code Snippet

This particular variable has been used extensively across different folders and files within the project. Manually renaming it everywhere would be incredibly time-consuming. Thankfully, I did some research and found a way to achieve this efficiently in Visual Studio Code (VS Code). Here are the steps involved:

1Select a variable name

variable name
Variable Name Highlighted

2Ctrl + Shift + F

The Search Sidebar will appear highlighting the variable references

VSCode search for variable references
VSCode Search for Variable References

As you can see I called this variable for more 200 times. Imagine, changing the variable name in the entire codebase one by one.

3Ctrl + Shift + H

Below the "Search" input text box, another input text box will appear labeled "Replace" for history.

Replace input text box
Replace Input Text Box

Now input your new variable name.

Changing the variable name
Changing the Variable Name

4Ctrl + Alt + Enter

Replace All using these keyboard shortcuts and a window will pop.

5Click Replace Button

Replace window confirmation
Replace Window Confirmation

Just like that!

Proof of Replacement
Proof of Replacement

Created

  • Sun May 12 2024
  • coding

    vscode

    word mass replacement

    refactoring

    coding workflow

    efficiency

    code editing

    development tools

    software development

    programming productivity

    coding tips

    Back on Top

    If you have any questions or feedback about this article feel free to email me here. Have a great day!

    More on LEARNINGS

      © 2024 Elly Mar