0

I want a behavior that whenever I press "Ctrl+B" it has to toggle the sidebar. If the sidebar becomes visible, then the focus should be on the sidebar. If the sidebar becomes hidden, then the focus should be back in the editor.

I want to avoid pressing ctrl+shift+e (a separate shortcut for focusing on the sidebar) after pressing ctrl+b. This is the same behavior that happens when I toggle a side tool window in Intellij, which I prefer.

I tried putting the below setting in keybindings.json, but it is not working.


    {
        "command": "runCommands",
        "key": "ctrl+b", // keybinding
        "args": {
          "commands": [
            // commands to run in sequence
            "workbench.action.togglefocusSideBar",
            "workbench.action.toggleSidebarVisibility"
          ]
        }
      }

FYI, I tried the above setting after seeing this question: Visual Studio Code keybindings - Running two or more commands with one shortcut

1 Answer 1

0

I fiddled around a bit and was able to get the required behavior with below JSON for keybindings


{
    "command": "runCommands",
    "key": "ctrl+b",
    "args": {
      "commands": [
        // commands to run in sequence
        "workbench.action.toggleSidebarVisibility",
        "workbench.view.explorer"
      ]
    },
    "when": "!sideBarVisible"
},
{
    "command": "workbench.action.toggleSidebarVisibility",
    "key": "ctrl+b",
    "when": "sideBarVisible"
}

2
  • fyi, if you didn't care about using the same key for both, there's ctrl+0 and ctrl+b.
    – starball
    Commented Jan 30 at 21:50
  • yes, I knew about these shortcuts. Wanted to minimize keystrokes, it to be quick, less shortcuts to memorize. Commented Jan 31 at 5:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.