Batch Search and Replace in VisualStudio Code

Have you ever needed to do search and replace multiple times against the same file or set of files. If so, the Batch Replacer extension for VisualStudio Code makes this very simple.

  1. Open a folder or file in VisualStudio Code
  2. Create a new file (no need to save it) and enter some search and replace instructions, e.g.

In the example above, I want 3 different replacements done in the order shown and I only want the replacements done to a specific file. The “in” command is followed by the path of the file relative to the root of the workspace open in VS Code. If the file is open, you can get it by right clicking on its tab and selecting “Copy relative path”.

3. Execute the replacer script

To run the batch replacements, you active tab must be the tab containing your replacement instructions. Then, hit CTRL+SHIFT+P -> Batch Replace. A status window will appear in the bottom right corner telling you how many files have been modified. If you want to batch replace across all files in your workspace, don’t include the “in” instruction.