skip to Main Content

I usually have vs-code with the side bar and the command prompt panel open

And I have to successively press ctrl-b and ctrl-t to show hide each one of them and concentrate on the code

Is there a shortcut key to do both things?


I found this related issue

2

Answers


  1. I tried fiddling with runCommands. You can give this a try (put in keybindings.json (open that file with Preferences: Open Keyboard Shortcuts (JSON) in the command palette)):

    {
        "key": "ctrl+b",
        "command": "runCommands",
        "args": {
            "commands": [
                "workbench.action.togglePanel",
                "workbench.action.toggleSidebarVisibility",
                // "workbench.action.toggleActivityBarVisibility", // might also want this
                "workbench.action.focusActiveEditorGroup", // doesn't work? not sure why :(
            ]
        }
    },
    

    Some obvious limitations: if they are out of sync, ex. View is open and Panel is closed, then this will not put them back in sync. I’m not sure how to do that- I couldn’t find commands for strictly opening/closing instead of toggling. Also, I can’t figure out how to send focus back to the editor at the end of the sequence, and I don’t really understand how it’s decided what area of the UI gets focus at the end. Unfortunately, this is the best I can think of right now. Maybe someone can improve on this.

    Login or Signup to reply.
  2. Try thess keybindings:

    {
      "key": "ctrl+b",                // whatever keybinding you want 
      "command": "runCommands",
      "args": {
          "commands": [
              "workbench.action.togglePanel",
              "workbench.action.toggleSidebarVisibility",
              "workbench.action.focusActiveEditorGroup"    // this works fine for me
          ]
      }
    },
    
    {
      "key": "ctrl+b",              // note same keybinding as above
      "command": "workbench.action.toggleSidebarVisibility",
      // "command": "workbench.action.closeSidebar",     // same effect
      "when": "sideBarVisible && !panelVisible"
    },
    
    {
      "key": "ctrl+b",              // note same keybinding as above
      "command": "workbench.action.togglePanel",
       // "command": "workbench.action.closePanel",  // doesn't seem to work when the terminal is focused
      "when": "panelVisible && !sideBarVisible"
    }
    

    The order is important, vscode matches keybindings from the bottom of keybindings.json up and you want the runCommands one evaluated last (as it doesn’t have a when clause and would always be triggered).

    These keybindings assume if one or the other sideBar/Panel are open you want to close it with the same keybinding as the main toggle. If you want to only open one when they are both closed. just use the standard keybindings for doing so.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search