I would like to use the View: Show Explorer command when the Sidebar is closed. And close the sidebar with the same key when the Sidebar is open.
So basically I want to let my Sidebar open with the Explorer by default (and also change the focus to the explorer by default), but also close the sidebar with the same key. This can be done with the when function in the vscode keyboard shortcuts, but I dont find the function which represents when the sidebar is open.
Already tried out: workbench.SideBar.visible: true 'sideBar.isOpen || sidebarIsOpen'
where are all these when functions listed in the documentation of VSCode?
just to be clear: it is one key which is used for two different shortcut actions - one is open+focus explorer and the other is toggle sidebar (but only when its open) - so it could also be named "close sidebar".
Try these keybindings in your keybindings.json
:
{
"key": "ctrl+shift+e", // when Explorer not open
// "command": "workbench.view.explorer", // either of these commands works
"command": "workbench.files.action.focusFilesExplorer",
"when": "!explorerViewletVisible"
},
{
"key": "ctrl+shift+e", // when Explorer open
"command": "workbench.action.toggleSidebarVisibility",
"when": "explorerViewletVisible"
}
How did I find those context keys
? See Inspect Context Keys Utility.
Developer: Inspect Context Keys
from the Command Palette and click anywhere in the vscode windowfind
input. For me, this appears at the very bottom and is tricky to see.explorerViewletVisible
looked most promising. Then I looked through the KeyBoard Shortcuts for "view explorer" and then "sidebar" to find commands I thought would work.
Here is my solution:
{
"key": "ctrl+k ctrl+b",
"command": "workbench.view.explorer",
"when": "viewContainer.workbench.view.explorer.enabled"
},
{
"key": "ctrl+k ctrl+b",
"command": "workbench.action.closeSidebar",
"when": "sideBarVisible"
},
Similar behavior to sublime text ctrl+k ctrl+b shortcut which toggles explorer view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With