NealVDV
NealVDV

Reputation: 2532

Open all files present in file content search result in VS Code

Is it anyway possible to open all files which found in my search query? Otherwise I need to double click 37 times for a single search result which seems suboptimal.

Example of search

enter image description here

Upvotes: 45

Views: 22009

Answers (7)

GMartinez
GMartinez

Reputation: 387

This worked for me on MacOS:

  • Click one of the files from the result list
  • Press Cmd+A twice to select all the files
  • Drag the selected files to an editor workspace on the right

Hope it helps someone else.

Upvotes: 5

user1947133
user1947133

Reputation: 21

You can shift + click to select all results in the search panel. (Alternatively you can press cmd/ctrl + A multiple times until all results are selected).

Then, you can drag all results into an open editor window and all files will be opened in separate tabs within the window.

At that point, you can search all the open files in the search panel by clicking the little book icon next to the "files to include" field.

Upvotes: 2

ngealy
ngealy

Reputation: 590

You can use the up/down arrow keys to highlight the file in the search results. Then press the right arrow and it will open the file without closing the search results. So you basically have to press down arrow, right arrow 37 times instead of clicking. Not great, but still faster.

Upvotes: 3

Cory Mawhorter
Cory Mawhorter

Reputation: 1811

Turns out you can shift + click to highlight all the results, and then you drag them over same as any other file. In vscode 1.71.2, at least.

I had 150 to open. Phew.

Upvotes: 34

Mathieu CAROFF
Mathieu CAROFF

Reputation: 1462

As stated in @Alex's comment, search.action.focusNextSearchResult is a great match for @NealVDV's use case. It can be run by pressing F4. It will open each result one after the other in a (writable) preview tab.

  • F4 (search.action.focusNextSearchResult) cycles forward through the search results
  • Shift+F4 (search.action.focusPreviousSearchResult) cycles backward through the search results

@jakub.g makes the remark that modifying a file in a way that removes them from the search result will make the focusNextSearchResult pointer restart from the beginning. A solution to this issue is to make sure that either:

  • The search result is never removed from the file while it is modified
  • The search result is always removed from the file by the modification

Upvotes: 11

Wladimir Gramacho
Wladimir Gramacho

Reputation: 647

There is this VS Code extension for that: Search - Open All Results

To install it, launch VS Code Quick Open (Ctrl+P) and run

ext install fabiospampinato.vscode-search-open-all-results

Upvotes: 9

Gabriel Ziegler
Gabriel Ziegler

Reputation: 391

I'm not sure how to do this with a VSCode native tool, but you could do this using VSCode terminal to find the pattern that you're looking for and open all files that match your search pattern. Something like the following:

grep -l "<Icon" * | xargs code
  • grep to look for your regex pattern with -l parameter to show only the filename.
  • xargs to pass the output as the argument for code.

This way you won't have to double click all the files one-by-one.

Upvotes: 4

Related Questions