Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find and replace all occurrences (in all files) in Visual Studio Code?

I can't figure out how to find and replace all occurrences of a word in different files using Visual Studio Code version 1.0.

I get the impression this should be possible since doing Ctrl + Shift + F allows me to simply search a folder, but i am clueless to how to proceed from here.

I looked in various key combination https://code.visualstudio.com/Docs/customization/keybindings

But I only found how to replace all occurrences in the open file (Ctrl + h)

All help gratefully appreciated, this is driving me crazy.

like image 431
Cisum Inas Avatar asked May 20 '16 12:05

Cisum Inas


People also ask

How do I replace all occurrences in Vscode?

Expand the Search widget to display the Replace text box. When you type text into the Replace text box, you will see a diff display of the pending changes. You can replace across all files from the Replace text box, replace all in one file or replace a single change.

How do I replace all files in Visual Studio?

On the Edit menu, expand Find and Replace. Choose Replace in Files. If the Find and Replace window is already open, on the toolbar, choose Replace in Files.

How do you edit multiple files vs code?

How to edit multiple lines in VS Code? With this keyboard shortcut, you can hold Ctrl and click the end of multiple lines to edit them all at once. That's it for now!


1 Answers

I'm using Visual Studio Code 1.8, and this feature is available. But it's a little tricky to understand at first, and (at the time of writing) the docs don't explain clearly how to use it, so here's how it works, step by step:

Invoke Replace in Files (under the Edit menu, or with shortcut Ctrl+Shift+H)

You'll see a standard Find/Replace input replacing the files pane on the left:

enter image description here

Enter your search string and the replace string, then press enter. It may churn for a second searching all files, then it'll show the proposed changes in all your project files -- but note, these changes haven't been made yet! Here's what it looks like:

enter image description here

Now you need to make the changes (and even after that, you have to save the modified files.)

You can make those changes in various ways:

  1. Make all changes to all files at once.

Click the replace icon next to your replace string (note: you'll get a dialog to confirm this bulk action.)

enter image description here

  1. Make all changes in a single file at once.

Click the replace icon next to the filename (note: the icon only shows up when you hover over the filename row)

enter image description here

  1. Make a single change in a single file.

Click the replace icon next to the individual change: (note: the icon only shows up when you hover over the change row)

enter image description here

Finally, don't forget to save!

All those files are now modified in the editor and not yet saved to disk (unless Auto Save is on).

Use File -> Save All (or Ctrl+Alt+S)

Update: I'm not sure when this was added, but if you click the "Replace all" button and see this dialog, clicking "Replace" will change and save all files in one click:

enter image description here

like image 147
Jeff Ward Avatar answered Sep 20 '22 20:09

Jeff Ward