Reputation: 625
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!
Upvotes: 49
Views: 19915
Reputation: 1
I expanded upon Demenetix's answer, by adding additional commands that allow me to swap between terminal and editor. It allows me to go back and forth fairly seamlessly using up
and down
as well as the left/right solutions.
{
"key": "cmd+alt+up",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
},
{
"key": "cmd+alt+down",
"command": "workbench.action.terminal.focusAtIndex1",
"when": "editorFocus"
},
Upvotes: 0
Reputation: 604
Add the following code to your keybindings.json file. This code sets up keybindings to switch between terminal tabs using "EasyMotion": Also install Easy motion from vs
{
"key": "ctrl+`",
"command": "easyMotion.quickMove",
"args": {
"inputType": "TerminalTabs",
"repeatCountFormat": "Number",
"matchFuzziness": "2"
},
"when": "terminalFocus"
}
]
Upvotes: 0
Reputation: 106
To switch between terminal you can use below commands
On Mac
This command will switch between terminal group. To find all commands:
command + shift + p (on mac)
Open keyboard shortcuts
Upvotes: 1
Reputation: 10646
on mac, ⇧⌘[ and ⇧⌘] worked for me.
this allows me to switch between different terminal instances when the terminal has focus. i use ⌘j to toggle focus between the terminal and editor.
source:
Navigate between terminal groups using focus next ⇧⌘] and focus previous ⇧⌘[.
https://code.visualstudio.com/docs/editor/integrated-terminal
Upvotes: 1
Reputation: 653
As for now it already switches tabs on the editor and terminal, just try ctrl + page up or ctrl + page down.
Upvotes: 0
Reputation: 721
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"
}
Upvotes: 70
Reputation: 2974
Here's the solution I built that works well for me on OSX.
It mimics the same shortcuts used in the editor to open new files (cmd+n) and switch between tabs (cmd+left|right) and the same shortcuts work for terminals when that view is in focus.
Hit 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)
Upvotes: 13
Reputation: 754
Based on Haini answer, Add the code below to your 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
Upvotes: 5
Reputation: 964
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"}
Upvotes: 27