Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hotkey for resizing the VS Code sidebar

Is there a way to resize the sidebar with a hotkey? For example, I currently have the "workbench.action.decreaseViewWidth" command bound to a key. But it appears that there is not a "workbench.action.decreaseSidebarWidth" command.

like image 686
Aristos Athens Avatar asked Sep 07 '25 02:09

Aristos Athens


2 Answers

I have done this which works well for me. Add this to your "keybindings.json". I have Swedish keyboard layout, so you might need to change the "key" part.

{
    "command": "runCommands",
    "key": "alt+[ArrowLeft]", // whatever keybinding
    "args": {
      "commands": [
        // commands to run in sequence
        "workbench.files.action.focusSideBar",
        "workbench.action.decreaseViewSize"
      ]
    }
  },
  {
    "command": "runCommands",
    "key": "alt+[ArrowRight]", // whatever keybinding
    "args": {
      "commands": [
        // commands to run in sequence
        "workbench.files.action.focusSideBar",
        "workbench.action.increaseViewSize"
      ]
    }
  }
like image 96
Databogdan Avatar answered Sep 11 '25 00:09

Databogdan


I've found the following to be a simple, successful mix of the previous answers. I've added additional instructions for those unfamiliar with keyboard shortcuts:

  1. Open "Preferences: Open Keyboard Shortcuts (JSON)".

  2. Add these entries to the JSON:

     {
         "key": "ctrl+alt+[ArrowLeft]",
         "command": "workbench.action.increaseViewSize"
     },
     {
         "key": "ctrl+alt+[ArrowRight]",
         "command": "workbench.action.decreaseViewSize"
     },
    
  3. Save changes.

  4. Press ctrl/control (^) and alt/option key (⎇) and left arrow (←).
    Verify sidebar decreases in size.

  5. Press ctrl/control (^) and alt/option key (⎇) and right arrow (→).
    Verify sidebar increases in size.

If your primary sidebar is on the right, consider swapping the commands in the shortcuts you add.

✅ Benefits:

  1. Allows editing via "Keyboard Shortcuts" interface.
    (cuz it does not require runCommands)
  2. Uses intuitive ← and → keys.⚠️
    (from https://stackoverflow.com/a/77051498/11817077)
  3. Does not overwrite macOS cursor navigation by word keyboard shortcut.⚠️

⚠️ Cons:

  1. The ← and → keys may not be intuitive if your current view is not the left sidebar.
  2. Might override another useful shortcut.
like image 38
Wesley B Avatar answered Sep 11 '25 02:09

Wesley B