How to search only in currently open files in vscode?

SearchVisual Studio-Code

Search Problem Overview


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.

Search Solutions


Solution 1 - Search

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

Here

Solution 2 - Search

As of v1.55 this will be enabled by default - the icon will always appear, you do not need to enable the setting mentioned below.

The v1.55 pre-release notes mention a "checkbox", but it isn't in Insiders Build so I think they mean the icon.


This is in the Stable Build v1.53 behind an experimental "flag":

Search > Experimental: Search in Open Editors

It is enabled by default in the Insiders' Build but requires a reload to take effect - so that the relevant option icon will appear. It is not enabled by default in the Stable Build (also requires a reload after enabling).

v1.53 Release Notes:

> This release comes with experimental support for searching in open > editors, which has been a highly requested feature for some time. This > feature is enabled by default in Insiders, and can be enabled with the > search.experimental.searchInOpenEditors setting in Stable.

See demo:

search in open editors demo

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).

Solution 3 - Search

"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".

Solution 4 - Search

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.

Solution 5 - Search

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

VS Code search toolbar

Solution 6 - Search

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

Solution 7 - Search

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.

Solution 8 - Search

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\

Solution 9 - Search

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.

Solution 10 - Search

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsneusseView Question on Stackoverflow
Solution 1 - SearchJmenaView Answer on Stackoverflow
Solution 2 - SearchMarkView Answer on Stackoverflow
Solution 3 - SearchKevinView Answer on Stackoverflow
Solution 4 - SearchRob LourensView Answer on Stackoverflow
Solution 5 - SearchArchulan RajakumaranView Answer on Stackoverflow
Solution 6 - Searchfst1View Answer on Stackoverflow
Solution 7 - SearchJacqui_BriggsView Answer on Stackoverflow
Solution 8 - SearchKeithJView Answer on Stackoverflow
Solution 9 - SearchWouter ScholsView Answer on Stackoverflow
Solution 10 - SearchRaynchow KuwwwView Answer on Stackoverflow