20

In the Search pane of the program, after I hit Enter, all files are listed, with some expanded to show results in a file, and others collapsed. I'm wondering firstly what determines the expansion of any given file, and secondly what I can do to expand all of them at once.

This question seems closest to mine, but it's about a different IDE, and the key commands it suggests for Windows had no apparent effect: Automatically expand all in Eclipse Search results

Mark
  • 143,421
  • 24
  • 428
  • 436
Lenoxus
  • 545
  • 1
  • 4
  • 19

2 Answers2

29

See this setting:

Search: Collapse Results in the Settings UI or

search.collapseResults: alwaysExpand in your settings.json file

The options are auto,alwaysCollapse, and alwaysExpand. auto is the default.

auto: Files with less than 10 results are expanded. Others are collapsed.

So you want the alwaysExpand option.

You can also toggle any file expanded/collapsed with the Space key or just expand any collapsed file with RightArrow.

Collapse with LeftArrow and collapse all with Ctrl+LeftArrow. Oddly, there is no expandAll binding or command.


And see https://stackoverflow.com/a/67307225/836330 for a command to collapse all the results that you can set to a keybinding:

workbench.files.action.collapseExplorerFolders as in

{
  "key": "alt+l",    // whatever you want
  "command": "search.action.collapseSearchResults",
  "when": "searchViewletFocus"   // if you want to limit it when focus is already on the search results area
}

in your keybindings.json.

v1.41 is making expanded search results the default, see https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_41.md#search

Expand all search results by default

Previously, if a full text search returned more than 10 results in a single file, it would appear collaped in the results tree. However, this sometimes made finding a particular result difficult, so with this release all results will appear expanded. You can set search.collapseResults to auto to revert to the old behaviour.

And see Visual Studio Code - Include context in search results for showing the search results in an editor.

Mark
  • 143,421
  • 24
  • 428
  • 436
  • 2
    Yeah, I also figured from the "Find All References" results, when you are in the state where some references are expanded, and some are collapsed, there is no Expand All option from the UI. (There is Collapse all though) :( – Gaurang Patel Sep 21 '20 at 01:10
  • 1
    Do you happen to know how to achieve a similar behavior when using "Find File References"? I got here searching for that, but no luck so far! Thanks edit: I just found https://github.com/microsoft/vscode-cpptools/issues/4333 but that is only for the c++ tools extension – MJB May 10 '21 at 14:14
19

There are two quick ways to expand all at any time:

  • Click the icon in the top right of the search panel that has a "+" inside a square. This toggles all items expanded/collapsed.

enter image description here

  • Use the command palette (Cmd-Shift-P) to trigger the "Search: Expand All" command. To make it quicker to access, you can add a custom keyboard shortcut: when looking at the "Expand All" search result in the command palette, click the gear icon next to it and it will take you to an editor for adding a shortcut binding.

Both of these only work for the Search panel though – despite the similarity, they do not work for the "Find All References" results panel.

Martin Zeltin
  • 2,496
  • 3
  • 18
  • 36
peterflynn
  • 4,667
  • 2
  • 27
  • 40