28

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

6
  • You can cut in half number of clicks if you disable preview :) "workbench.editor.enablePreview": false
    – Alex
    Nov 10, 2017 at 11:43
  • Why do you even need to open them all anyway?
    – Alex
    Nov 10, 2017 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, 2017 at 16:42
  • 3
    I would've just used search.action.focusNextSearchResult F4 keybinding
    – Alex
    Nov 10, 2017 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 8, 2018 at 15:05

5 Answers 5

11

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
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
  • 3
    From the plugin page: "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, 2020 at 6: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 3, 2022 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
    – a.t.
    Nov 3, 2022 at 15:24
9

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.

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.

2
  • On Windows, from Powershell, with VScode 1.42.1, this opens a single new VSCode window, without any file opened in it. Mar 8, 2020 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, 2020 at 0:58
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.