VS Code Key Binding for quick switching between terminal screens?

I'm trying to find out if there is a way to configure the key binding to provide a quick transition between the terminal windows that I opened in the built-in terminal, instead of pressing the selector down each time, Does anyone know a command for this when creating a private key binding or Where can I see a list of all the possible commands for VSC? Thank you in advance!

+22
source share
4 answers

From the Microsoft documentation there is a hint:

Tip: if you are heavily using multiple terminals, you can add the key designated bindings for the focusNext, focusPrevious and kill commands in the Key Bindings section to allow navigation between them using only the keyboard.

From here :

Other terminal commands are available and can be tied to your preferred keyboard shortcuts. They are: workbench.action.terminal.focus: focus the terminal. It's like switching, but focuses the terminal, and does not hide 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 keyboard shortcuts to your preferred keyboard shortcuts, and you're done.

This may not be a solution for directly navigating to a terminal (like vims gt2 for example), but this is definitely the start.


Change: Just played around and found that you can also focus on a specific terminal. Just add any of these commands to your keybindings.json and you keybindings.json done!

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

for example { "key": "yourkeybinding", "command": "workbench.action.terminal.focusAtIndex1"}

+13
source

If you want something that may seem a little smoother than using arbitrary key bindings, you can make Ctrl + Tab and Ctrl + Shift + Tab work both for switching the editor and for switching the terminal.

Open the keyboard shortcut file by searching ctrl+shift+p to search for the keyboard file . 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" } 
+23
source

Here the solution I built works well for me on OSX.

It simulates the same shortcuts that are used in the editor to open new files (cmd + n) and switch between tabs (cmd + left | right) and the same shortcuts for terminals when this view is in focus.

Press cmd+shift+p and type keyboard to find Preferences: Open Keyboard Shortcuts File

Add the following to the keybindings.json file and save it.

 { "key": "cmd+alt+right", "command": "workbench.action.terminal.focusNext", "when": "terminalFocus" }, { "key": "cmd+alt+left", "command": "workbench.action.terminal.focusPrevious", "when": "terminalFocus" }, { "key": "cmd+n", "command": "workbench.action.terminal.new", "when": "terminalFocus" }, { "key": "cmd+w", "command": "workbench.action.terminal.kill", "when": "terminalFocus" } 

It also does the same for closing terminals (cmd + w)

+5
source

Based on Haini's answer, add the code below in keybindings.json

 { "key": "shift+up", "command": "workbench.action.terminal.focusPrevious", "when": "terminalFocus" }, { "key": "shift+down", "command": "workbench.action.terminal.focusNext", "when": "terminalFocus" } 

Now you can switch between terminals using shift + down or shift + up

+3
source

All Articles