Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In VS Code file searching, can I expand all results?

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

like image 982
Lenoxus Avatar asked Sep 04 '19 13:09

Lenoxus


People also ask

How do you expand everything in VS Code?

Fold All (Ctrl+K Ctrl+0) folds all regions in the editor. Unfold All (Ctrl+K Ctrl+J) unfolds all regions in the editor. Fold Level X (Ctrl+K Ctrl+2 for level 2) folds all regions of level X, except the region at the current cursor position.

How do I expand all methods in visual studio?

CTRL + M + P will expand all and disable outlining. CTRL + M + M will collapse/expand the current section.

How do you search all in VS Code?

VS Code allows you to quickly search over all files in the currently-opened folder. Press Ctrl+Shift+F and enter in your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location.


2 Answers

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.

like image 72
Mark Avatar answered Oct 13 '22 14:10

Mark


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.
  • 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.

like image 26
peterflynn Avatar answered Oct 13 '22 15:10

peterflynn