32

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

NealVDV
  • 2,302
  • 3
  • 26
  • 51
  • You can cut in half number of clicks if you disable preview :) `"workbench.editor.enablePreview": false` – Alex Nov 10 '17 at 11:43
  • Why do you even need to open them all anyway? – Alex Nov 10 '17 at 11:45
  • 1
    @Alex because I need to change for example `position="left" anotherProp="somevalue"`and they are not in the same order or it depends on the otherprop. So a simple replace won't work – NealVDV Nov 10 '17 at 16:42
  • 3
    I would've just used `search.action.focusNextSearchResult` **F4** keybinding – Alex Nov 10 '17 at 17:15
  • @Alex `F4` seems interesting, but if you need to change some of the files in a way that makes them disappear from search results, the pointer is reset and `F4` starts the cycle again from the beginning. – jakub.g Aug 08 '18 at 15:05
  • I couldn't get F4 working for some reason. Now I just search for all files in the file system and open them all in VS Code. Really annoying that this doesn't work directly in VS Code. – Kokodoko Nov 09 '21 at 11:35

5 Answers5

19

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.

Cory Mawhorter
  • 1,583
  • 18
  • 22
10

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
Mathieu CAROFF
  • 1,230
  • 13
  • 19
9

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

  • 3
    From the [plugin page](https://marketplace.visualstudio.com/items?itemName=fabiospampinato.vscode-search-open-all-results): "There isn't really a proper API for implementing this, therefor the way this works is a bit hacky, you might find some bugs with it. Try to use this on search queries that produce 1, or very few, results per file." Bugs indeed. Removed and resorted to hammering `search.action.focusNextSearchResult` … – panepeter Nov 13 '20 at 06:51
  • Thank you for the suggestion, after installing the extension, I ran a search with 150 files with roughly 15 hits per file. However when I press `CTRL+P` and type: `>Open All Results`, it will loop over the first ~10 hits only. So I tried: `"searchOpenAllResults.fileResultsLimit": 300,` and re-loading the VScode. That did not change the behaviour. Do you know how to make it open all results instead? – a.t. Nov 03 '22 at 15:03
  • Note, I added the settings incorrectly, I should have included the settings in the pre-existing `.vscode` settings `json`, instead of adding them as a new separate dictionary. More details [here](https://github.com/fabiospampinato/vscode-search-open-all-results/issues/4#issuecomment-1302276969) – a.t. Nov 03 '22 at 15:24
4

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.

Gabriel Ziegler
  • 361
  • 3
  • 18
  • On Windows, from Powershell, with VScode 1.42.1, this opens a single new VSCode window, **without any file opened in it**. – Mathieu CAROFF Mar 08 '20 at 21:41
  • 2
    Try this if you only want to open files with certain name: find . -iname CMakeLists.txt | xargs code – colddie Apr 25 '20 at 00:58
1

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.

ngealy
  • 561
  • 4
  • 5