VSCode - how to close the search result sidebar panel?

Viewed 3540

I disabled the activity bar (the leftmost panel with shortcuts buttons).

When I search for something the search results shown in side bar, replacing the file explorer. When I'm done with the search - how can I close the search results and see the file explorer bar again?

Given that there's no activity bar with the file structure bar shortcut on it? I tried clicking escape but the file results won't disappear. There's not even a button to close it.

5 Answers

I assume that you see something like this when you realize a search:

Search sidebar Visual Studio Code

You can go back to the Explorer sidebar on two different ways:

  1. Press in the File icon that is up of the Search icon
  2. Use the Ctrl+Shift+E shortcut

After pulling up search with Cmd+Shift+F, I'm able to close with Cmd+B on Mac.

This is a frustrating takeover of screen real-estate!

The UI for VSCode's search results pane aren't fully like a modal and they're not quite like a vertical tab. If you hover over the icons in the left-hand margin, you'll see the keyboard shortcuts for the "Explorer" and for "Search". On a Mac, it's Command + 1 to toggle the explorer and Command + 3 to toggle the search results.

However, toggling the explorer may not leave your screen the way it was before the search, so this isn't really the clean solution many of us were hoping for.

Here's a related question/answer with instructions for creating a key-binding.

The closest I have been able to come to the "expected behavior" I desire is to add the following rule to the top of my keybindings.json:

{
  "key": "Escape",
  "command": "workbench.view.explorer",
  "when": "searchViewletVisible"
}

The when clause helps scope its effect, but it may conflict with other commands.

To close the search bar when using "Edit", "Find in Files" or "Replace in Files" in order to collapse the search results and/or panel I usually right-click on the "Search" label at the top of the results and click "Hide Side Bar" in the resulting drop down.

In my case I wanted to close the sidebar when press Escape:

keybindings.json

{
    "key": "Escape",
    "command": "workbench.action.closeSidebar",
    "when": "sideBarFocus"
}

Resource

https://stackoverflow.com/a/64704130/5994546

Related