I’m currently updating an old project in which there is a lot of files.
In those files, I need to modify some lines that look slightly the same (i.e. for which I can make a regex).
I don’t want to update each file one by one.
Therefore, in VS Code, I’m searching for a way to modify them at the same time.
I thought about using the "Workspace Search Menu" of VS Code in order to search the lines matching a specific regex through all my files.
Once I have found all the matching lines, I open my search result in editor mode to
modify those lines.
However, I don’t know how to apply my changes to the files once I’m done.
Here is my question :
"Is it possible and if so how can I do that ?"
Btw, I am only using VS Code and I don’t mind downloading some extensions if it’s needed.
Note : To open the "Workspace Search Menu" you need to press Ctrl+Shift+F
in Windows & Linux or Cmd+Shift+F
in Mac.
Edit : I do know how to replace each occurence of a line with something else in all files using Ctrl+Shift+H
(or Cmd+Shift+H
).
However in my case, the changes I want to make will depend on the line.
For example :
Before the changes :
In file
a.js
let a = 2;
In file
b.js
let b = "Hello World !";
After the changes :
In file
a.js
const a=2;
In file
b.js
const b="Hello World !";
Note that the line in a.js
and b.js
aren’t the same before nor after the changes.
However, we could say that they have been changed in the same way.
2
Answers
I found a VS Code extension that allowed me to do exactly what I wanted. This extension is simply called Search Editor: Apply Changes.
when you are in
Workspace Search Menu
there is a small carret icon on left of search field. you can click on that to open replace field.OR
You can invoke find and replace in all files using
Ctrl+Shift+H