sneusse
sneusse

Reputation: 1691

How to search only in currently open files in vscode?

I usually work on larger projects with many files that would contain the search query. So I would open the files I want to modify and do a find/replace across all currently opened files. Can this be done in vs code?

The feature I'm looking for is implemented in Notepad++, but I'd prefer not to have to switch editors for this task.

Upvotes: 105

Views: 37579

Answers (10)

Mark
Mark

Reputation: 180631

The ability to search only in the open editors is in the Stable Build v1.55.

search in open editors only

As you can see, the icon is at the end of the files to include input so you will have to have that showing (click the three dots ... just below the search options if files to include is not already showing).

Upvotes: 93

Raynchow Kuwww
Raynchow Kuwww

Reputation: 11

This extension is what I use for this purpose. You may need to change the keybinding if there is a conflict.

Upvotes: 1

Sheldon Osotsi
Sheldon Osotsi

Reputation: 81

The best way to find something you are searching for within a specific file in vs code would be:

  • Ctrl + p then pressing @ on the search bar.

It will give you a list of all functions on the file, which makes it easier to track something down.

Upvotes: 1

Wouter Schols
Wouter Schols

Reputation: 43

The answer was already mentioned (and accepted above) indeed typing ./ in the files to exclude box of the search window will allow you to only search in open files.

However the response mentioned that he was unsure why this worked. VSCode allows you to exclude all files in a directory by writing the directory in the exclude box. The directory . is the directory where VSCode is opened ie the root directory. The filter ./ excludes all files in the VSCodes root directory so all files are excluded. However opened files ignore any exclude filter. So if you exclude all files only the opened files will be searched.

Upvotes: 1

Archulan R
Archulan R

Reputation: 478

Hit Ctrl + Shift + F and enable the icon at the end of the 'file to include' text field

VS Code search toolbar

Upvotes: 10

fst1
fst1

Reputation: 107

There is a checkbox for this in the "files to include" field since version 1.55 (march 2021).

Upvotes: 3

Jmena
Jmena

Reputation: 721

For me somehow it works just by typing ./ in the files to exclude field.

Here

Upvotes: 55

KeithJ
KeithJ

Reputation: 169

As an alternative to using Visual Studio Code itself, you can just search the file contents within the folder where unsaved files open in Visual Studio Code are located. This would be in one of these locations depending on which OS you are running:

  • Linux: /tmp/ (someone else running Linux can verify this)
  • macOS: ~/Library/Application\ Support/Code/Backups/
  • Windows: %APPDATA%\Code\User\

Upvotes: 1

Kevin
Kevin

Reputation: 2929

"Search: target particular set of files #20530" located here: https://github.com/Microsoft/vscode/issues/20530

Is tracking a search "scope" such as "all open files".

Upvotes: 17

Rob Lourens
Rob Lourens

Reputation: 16089

I don't think there's a way to do this. You can make a feature request on github. I think an extension could do it though.

Upvotes: 5

Related Questions