7

I need to replace some text in only the files that are currently opened.

Such as my project contains a.html, b.html and c.html; but I opened only a.html and b.html, so the replace won't affect c.html

Is there a way to find and replace the occurrences at once instead of going through those files one by one?

Hao Wu
  • 17,573
  • 6
  • 28
  • 60
  • 1
    But I need to replace just opened files, not the whole project... – Hao Wu May 23 '19 at 06:32
  • @HaoWu kindly check my updated answer – AbdulAzeem May 23 '19 at 06:34
  • @HaoWu click the three dots it will show files to include and exclude. In that you type your files names. – AbdulAzeem May 23 '19 at 06:37
  • 1
    Does this answer your question? [How to search only in currently open files in vscode?](https://stackoverflow.com/questions/42011289/how-to-search-only-in-currently-open-files-in-vscode) (specifically, [this answer](https://stackoverflow.com/a/65851872/2745495) that shows new experimental feature in VS Code 1.53) – Gino Mempin Feb 06 '21 at 01:48

2 Answers2

11

If you add ./ in files to exclude it will only look in open files.

Search/replace screenshot

Peter Hedberg
  • 3,487
  • 2
  • 28
  • 36
1

enter image description here

Use this panel in VS Code (in the menu choose "Edit > Replace in Files") and replace all occurrences in project files. And you can also specify files to include and files to exclude.

Here is a shortcut to open "Replace in Files" panel:

Ctrl + Shift + H

informatik01
  • 16,038
  • 10
  • 74
  • 104
AbdulAzeem
  • 529
  • 4
  • 8
  • 1
    It works, thanks! I just wish there's a better way to do this, that I still need to type in all the opened file names... – Hao Wu May 23 '19 at 06:38