Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code Key Binding for quick switch between terminal screens?

I'm trying to figure out if there is a way to set up a key binding to allow a quick switch between the terminal windows I have open in the built in terminal rather than having to click on the drop down selector each time. Does anyone know the command for this when making a personal key binding or where I can see a list of all the possible commands for VSC? Thank you in advance!

like image 435
pbie42 Avatar asked May 19 '17 08:05

pbie42


People also ask

How do you toggle between terminals in VS Code?

Once the cursor is in the terminal section you can use ctrl+x ctrl+up or ctrl+x ctrl+down to cycle through the active terminals (note that moving between on-screen split terminals is done with ctrl+x left or ctrl+x right ). cmd-J is still used to hide/show the terminal pane.

How do you quickly switch tabs in VS Code?

When using Visual Studio Code on Windows, you can use CTRL + PAGE_UP to switch to the previous tab, and CTRL + PAGE_DN to switch to the next tab. You also have the ability to switch to tabs based on their (non-zero relative) index. You can do so, by pressing and holding ALT , followed by a number (1 through 9).

What is Ctrl K in VS Code?

To launch the Define Keybinding widget, press Ctrl+K Ctrl+K. The widget listens for key presses and renders the serialized JSON representation in the text box and below it, the keys that VS Code has detected under your current keyboard layout.

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.


2 Answers

If you want something that might feel a bit more fluid than using arbitrary key bindings, you can get Ctrl+Tab and Ctrl+Shift+Tab working for both editor switching and terminal switching.

Open your keybindings file with ctrl+shift+p search for Open Keyboard Shortcuts (JSON). Then add..

{    "key": "ctrl+tab",               "command": "workbench.action.openNextRecentlyUsedEditorInGroup",   "when": "editorFocus"  }, { "key": "shift+ctrl+tab",         "command": "workbench.action.openPreviousRecentlyUsedEditorInGroup",   "when": "editorFocus"  }, {   "key": "ctrl+tab",   "command": "workbench.action.terminal.focusNext",   "when": "terminalFocus" }, {   "key": "ctrl+shift+tab",   "command": "workbench.action.terminal.focusPrevious",   "when": "terminalFocus" } 
like image 178
Patrick Loyd Avatar answered Sep 19 '22 01:09

Patrick Loyd


From Microsofts Documentation there is a tip:

Tip: If you use multiple terminals extensively, you can add key bindings for the focusNext, focusPrevious and kill commands outlined in the Key Bindings section to allow navigation between them using only the keyboard.

From here:

Other terminal commands are available and can be bound to your preferred keyboard shortcuts. They are: workbench.action.terminal.focus: Focus the terminal. This is like toggle but focuses the terminal instead of hiding it, if it is visible.

workbench.action.terminal.focusNext: Focuses the next terminal instance.  workbench.action.terminal.focusPrevious: Focuses the previous terminal instance.  workbench.action.terminal.kill: Remove the current terminal instance. workbench.action.terminal.runSelectedText: Run the selected text in the terminal instance. 

Just assign these shortcuts to your preferred keybindings and you are good to go.

That might not be a solution for jumping directly to a terminal (e.g. like vims gt2) but it certainly is a start.


Edit: Just toyed around and found that you can also focus on a specific terminal. Just add any of these commands to your keybindings.json and you are good to go!

// - workbench.action.terminal.focusAtIndex1 // - workbench.action.terminal.focusAtIndex2 // - workbench.action.terminal.focusAtIndex3 // - workbench.action.terminal.focusAtIndex4 // - workbench.action.terminal.focusAtIndex5 // - workbench.action.terminal.focusAtIndex6 // - workbench.action.terminal.focusAtIndex7 // - workbench.action.terminal.focusAtIndex8 // - workbench.action.terminal.focusAtIndex9 

e.g. { "key": "yourkeybinding", "command": "workbench.action.terminal.focusAtIndex1"}

like image 24
Haini Avatar answered Sep 18 '22 01:09

Haini