Search code examples
visual-studio-codekeyboard-shortcuts

How to hide and show side bar with the same shortcut in Visual Studio code


I have the following shortcut for VS Code on MacOS:

  {
    "key": "cmd+1",
    "command": "workbench.scm.focus"
  },

That will focus the source control pane and show it if the side bar is not visible. What I want now is to to hide the side bar when I click Cmd+1 again and the scm pane is open. Right now I can hide the side pane with Cmd+B:

enter image description here

Is there a way to change that? I have been trying to make a conditional shortcut but I have not found the way.


Solution

  •   {
        "key": "cmd+1",
        "command": "workbench.scm.focus",
        "when": "!workbench.scm.visible"
      },
      {
        "key": "cmd+1",
        "command": "workbench.action.toggleSidebarVisibility",
        "when": "workbench.scm.visible"
      },