51

It would be very useful for me if there was a keyboard shortcut for moving focus to the sidebar in Visual Studio Code. I have seen the question Is there a shortcut to hide the side bar in Visual Studio Code? but this is not what I want.

I want to get focus there without using the mouse so that I can select another file listed in the sidebar without having to use the mouse.

Benilda Key
  • 2,836
  • 1
  • 22
  • 34

5 Answers5

98

Ctrl0 is the default binding of View: Focus into Side Bar command that focuses sidebar regardless what it shows at the moment - be it Explorer, Source Control, Extensions or any other pane. (Or reveals its last visible state.)

Zero (0) in this key combination represents character that "English-keyboard-layout" zero key in the top 'numerical' row produces in current regional keyboard layout. It is not the zero key in the "NumPad".

Like most other actions it is easily discoverable either in the Command Palette (F1 or CtrlShiftP):

command palette with query: (greater-than sign) focus sidebar. Sole highlighted result reads "View: focus into Side Bar", words "focus" and "side bar" are emphasized. Keyboard shortcut hint reads "Ctrl + é" (control key plus Latin letter E with acute)

(N.B. é instead of 0 due to aforementioned regional layout in effect), or in the Keyboard Shortcuts settings page (CtrlK CtrlS):

VSC Keyboard Shortcuts settings with query "focus sidebar" showing sole Command result: "Focus into Side Bar", words "focus" and "side bar" are emphasized. There is the command ID that reads "workbench.action.focusSideBar"


Btw Ctrl1 .. 3 focuses editor groups respectively.


If you'd like to have this (or other) key combination to act like two way "focus toggle" between editor and sidebar (like Show Explorer behaves), you can alter your settings accordingly using distinct actions with identical key combination differentiated by excluding "when" conditions. Resulting part of keybindings.json would then be:

  { // Unbind unconditional default using "minus" (-) before command
    "key": "ctrl+0",
    "command": "-workbench.action.focusSideBar"
  },
  { // Move focus to the SideBar if not (!) there
    "key": "ctrl+0",
    "when": "!sideBarFocus",
    "command": "workbench.action.focusSideBar"
  },
  { // Move focus to the Editor, if currently in the SideBar
    "key": "ctrl+0",
    "when": "sideBarFocus",
    "command": "workbench.action.focusActiveEditorGroup"
  },
myf
  • 9,874
  • 2
  • 37
  • 49
  • Once focus lands in the sidebar, it seems to get stuck. That is, when the Explorer tab is open, pressing Control+0 moves focus to the sidebar, but then when you try to navigate through the tree nothing happens. The arrow keys do nothing. The tab key does nothing. So far it appears that Visual Studio Code is in violation of WCAG Guideline 2.1, specifically 2.1.2 No Keyboard Trap (http://www.w3.org/TR/2008/REC-WCAG20-20081211/#keyboard-operation-trapping). – Benilda Key Apr 06 '18 at 19:07
  • Yes, sometimes there are some border cases where keyboard navigation appears to be stuck, but overal VSC developers invests a lot of efforts making it as keaboard accessible as possible: there is a bunch of workarounds for such situations: ctrl+q, command palette or advice shown in alt+f1 dialog. – myf Apr 06 '18 at 19:32
  • Anyway, if you can reproduce some nasty keyboard trap (best in a clean profile, https://stackoverflow.com/q/49667641) it would be definitely worth reporting at https://github.com/Microsoft/vscode/issues/ – myf Apr 06 '18 at 19:37
  • I tried to reproduce the keyboard trap issue I encountered again today and I could not. I did install an update for Visual Studio Code today so perhaps they fixed it already. – Benilda Key Apr 11 '18 at 14:11
26

These are the different shortcuts to focus on the various components(in order of the icons) of the sidebar.

  1. File Explorer: ctrlshifte

  2. Search: ctrlshiftf

  3. Source Control: ctrlshiftg

  4. Debug: ctrlshiftd

  5. Extensions: ctrlshiftx

To toggle the visibility of the sidebar, just press ctrlb

Chirag Bhansali
  • 1,900
  • 1
  • 15
  • 22
12

Cmd + Shift + E works for me. See screenshot

enter image description here

Lance Harper
  • 2,216
  • 14
  • 11
6

you can hover over the icons in the sidebar if you want a tooltip telling you what shortcut each tab has

enter image description here

feihcsim
  • 1,444
  • 2
  • 17
  • 33
0

Mine, on windows, numpad key doesn't work. I have to use the other Zero key that is on the top of the keyboard.

enter image description here

Behzad
  • 1,740
  • 1
  • 22
  • 49