Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a shortcut to move focus to the sidebar in Visual Studio Code?

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.

like image 427
Ben Key Avatar asked Apr 04 '18 23:04

Ben Key


People also ask

What is Ctrl Shift P in VS Code?

You can define a keyboard shortcut for any task. From the Command Palette (Ctrl+Shift+P), select Preferences: Open Keyboard Shortcuts File, bind the desired shortcut to the workbench.

What is Ctrl Shift L in VS Code?

Press Ctrl + Shift + L . This will select all words that match your current selection. It also adds a cursor to each text span matching your current selection. Simply start typing your replacement text and vscode will start replacing all instances of text matching your selection in-editor as you type.

What is Ctrl Shift F in Visual Studio?

Ctrl-Shift-F is used to find all the ocuurance of a string with in entire solution and display find result window as shown below. Ctrl-F is used to find a string in the current document, project and all open documents one by one.


2 Answers

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 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 be

  { // Unbind unconditional default
    "key": "ctrl+0",
    "command": "-workbench.action.focusSideBar"
  },
  { // to ←
    "key": "ctrl+0",
    "when": "!sideBarFocus",
    "command": "workbench.action.focusSideBar"
  },
  { // from →
    "key": "ctrl+0",
    "when": "sideBarFocus",
    "command": "workbench.action.focusActiveEditorGroup"
  },
like image 159
myf Avatar answered Oct 06 '22 20:10

myf


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

like image 23
Chirag Bhansali Avatar answered Oct 06 '22 18:10

Chirag Bhansali