VSCode keybinding to hide Explorer

Visual Studio-CodeKeyboard Shortcuts

Visual Studio-Code Problem Overview


Is there any keybinding in VSCode that can hide Explorer, like Ctrl+Shift+E works for showing it?

I hate reaching for the mouse and I don't have enough screen space to keep Explorer always on.

Visual Studio-Code Solutions


Solution 1 - Visual Studio-Code

Toggle Sidebar Visibility: Ctrl+B (Windows/Linux)

If you're a MacOS user, then it's + b.

Visual Studio Code Key Bindings

Solution 2 - Visual Studio-Code

If you're a MacOS user, then it's + b.

I won't leave you without a GIF.

shortcut for mac VS Code

Solution 3 - Visual Studio-Code

Some clarification: usually Ctrl+B is used for closing a sidebar (not toggling by default). So if you haven't a sidebar and want to open it - press the following combination: Ctrl+Shift+E(opens the sidebar with active explorer) or Ctr+Shift+F (with active search) etc. Now if you want to get rid of a sidebar press Ctrl+B. Note if you're using vim plugin and want to close a sidebar but currently is working on your code - first make a sidebar active by pressing (Ctrl+Shift+E) and then close it via Ctrl+B.

update: recently I've discovered that Ctrl+Shift+E doesn't play nice with my neo vim plugin, so in order to overcome it there is another shortcut to open sidebar explorer: single press of Ctrl+0 to open it and pressing of Ctrl+0 one more time to get focus on it.

Solution 4 - Visual Studio-Code

I'm using Visual Studio keymap. On my keyboard shortcuts, Toggle Side Bar Visibility was set to CTRL+B but doesn't works.

I do remap to CTRL+B and works fine.

File > Preferences > KeyBoard ShortCuts

Solution 5 - Visual Studio-Code

VSCode default Keybinding for Toggling "Side Bar" aka "Explorer" is CTRL+B. Just CTRL+B alone works fine.

Solution 6 - Visual Studio-Code

If you want to use cmd+b to open and close your explorer add these lines to your keybindings.json

    {
        "key": "cmd+e",
        "command": "workbench.view.explorer"
    },
    {
        "key": "cmd+e",
        "command": "-workbench.view.explorer"
    },
    {
        "key": "cmd+e",
        "command": "workbench.action.toggleSidebarVisibility",
        "when": "explorerViewletVisible"
    },
    {
        "key": "cmd+e",
        "command": "-workbench.action.toggleSidebarVisibility",
        "when": "explorerViewletVisible"
    },

Of course, you must replace the "e" with "b" !

Solution 7 - Visual Studio-Code

In Mac, it's cmd+B and in windows, it's ctrl+B

Solution 8 - Visual Studio-Code

This is an extension of @tsm's answer.

If you want to toggle Explorer using ctrl+e then use the following keybindings.

{
    "key": "ctrl+e",
    "command": "-workbench.action.quickOpen"
},
{
    "key": "ctrl+e",
    "command": "-workbench.action.quickOpenNavigateNextInFilePicker",
    "when": "inFilesPicker && inQuickOpen"
},
{
    "key": "ctrl+b",
    "command": "-workbench.action.toggleSidebarVisibility"
},
{
    "key": "ctrl+e",
    "command": "workbench.view.explorer"
},
{
    "key": "ctrl+e",
    "command": "workbench.action.toggleSidebarVisibility",
    "when": "activeViewlet == 'workbench.view.explorer' || activeViewlet == 'workbench.view.search'|| activeViewlet == 'workbench.view.scm'|| activeViewlet == 'workbench.view.debug'|| activeViewlet == 'workbench.view.extensions' || activeViewlet == 'workbench.view.extension.test'|| activeViewlet == 'workbench.view.extension.bookmarks'|| activeViewlet == 'workbench.view.extension.project-manager' || activeViewlet == 'workbench.view.extension.gitlens'|| activeViewlet == 'workbench.view.extension.todo-tree-container'|| activeViewlet == 'snippet-explorer'"
}

Here, the first two keybindings are to unbind ctrl+e. So, it depends on which commands you are currently using with ctrl+e.

the third keybinding is to unbind ctrl+b as you will no longer need ctrl+b to Toggle Sidebar Visibility.

The fourth keybinding is to view explorer using ctrl+e.

Now the interesting part. The fifth keybinding. Here, I am saying: "if sidebar is open and I press ctrl+e then close the sidebar."

Please understand that, one of the way to open a Sidebar is to click one of the Sidebar Icons. When we click on a particular Sidebar Icon, we get it's corresponding Sidebar View.

To create this keybinding we have to get all the Contexts (in this case, value of activeViewlet) of each Sidebar Views.

How to get Contexts can be found on VSCODE Accurate keybinding, want to know current context. How to do?. This same information can also be found on the documentation.

So, long story short, I found the contexts by running Developer: Inspect Context Keys in command pallet and observing the Developer Tools.

  1. Open VSCode debugger (click Help > Toggle Developer Tools).
  2. Run Developer: Inspect Context Keys in command pallet
  3. Open the sidebar you want to know the context (value of activeViewlet) of.
  4. Get the context from the Developer Tool's Console.

Now, add these contexts (for example workbench.view.explorer, workbench.view.search, workbench.view.scm etc.) in the when key.

Update 1:

You actually do not need to find the contexts. You can just use:

{
    "key": "ctrl+e",
    "command": "workbench.action.toggleSidebarVisibility",
    "when": "activeViewlet != ''"
}

Instead of

{
    "key": "ctrl+e",
    "command": "workbench.action.toggleSidebarVisibility",
    "when": "activeViewlet == 'workbench.view.explorer' || activeViewlet == 'workbench.view.search'|| activeViewlet == 'workbench.view.scm'|| activeViewlet == 'workbench.view.debug'|| activeViewlet == 'workbench.view.extensions' || activeViewlet == 'workbench.view.extension.test'|| activeViewlet == 'workbench.view.extension.bookmarks'|| activeViewlet == 'workbench.view.extension.project-manager' || activeViewlet == 'workbench.view.extension.gitlens'|| activeViewlet == 'workbench.view.extension.todo-tree-container'|| activeViewlet == 'snippet-explorer'"
}

Solution 9 - Visual Studio-Code

I have to say CTRL+B stands for calling out the sider bar.

To hide the sider bar, you should type: CTRl+\

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCristian MuscaluView Question on Stackoverflow
Solution 1 - Visual Studio-CodehmoritzView Answer on Stackoverflow
Solution 2 - Visual Studio-CodeAhmad AwaisView Answer on Stackoverflow
Solution 3 - Visual Studio-CodedaGoView Answer on Stackoverflow
Solution 4 - Visual Studio-CodeMaicon HeckView Answer on Stackoverflow
Solution 5 - Visual Studio-Codesulara.pereraView Answer on Stackoverflow
Solution 6 - Visual Studio-CodetsmView Answer on Stackoverflow
Solution 7 - Visual Studio-CodeSandeep AmarnathView Answer on Stackoverflow
Solution 8 - Visual Studio-CodeAhmad IsmailView Answer on Stackoverflow
Solution 9 - Visual Studio-CodeshenView Answer on Stackoverflow