22

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,092
  • 2
  • 23
  • 48
  • 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

3 Answers3

8

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
  • 890
  • 11
  • 17
7

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
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
  • 308
  • 3
  • 16
  • 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