1190

Does anyone know the keyboard shortcut (Mac and Linux) to switch the focus between editor and integrated terminal in Visual Studio Code?

10
  • 81
    ctrl + ' ` ' will be the best #-> Linux Commented Jan 24, 2018 at 15:40
  • 49
    ctrl + ' ` ' works also on OS X without any additional key binding. Commented Feb 5, 2019 at 3:25
  • 20
    ctrl + ' ` ' works with Windows flawlessly too!
    – Ehtesham Z
    Commented Jan 13, 2020 at 22:07
  • 15
    The problem with CTRL+` is that it creates a new terminal even if one already exists.
    – Guss
    Commented Aug 23, 2020 at 8:26
  • 17
    @Guss not anymore (v1.55.0)
    – danno
    Commented Apr 26, 2021 at 0:48

29 Answers 29

1967

While there are a lot of modal toggles and navigation shortcuts for VS Code, there isn't one specifically for "move from editor to terminal, and back again". However you can compose the two steps by overloading the key and using the when clause.


Solution

You can achieve the desired effect by adding the appropriate settings to the keybindings.json file. Here are the required steps:

  1. Open the Command Palette (Ctrl+Shift+P Windows/Linux or P Mac).

  2. Type "Preferences: Open Keyboard Shortcuts (JSON)" and press Enter.

  3. Add the following entries to the keybindings.json file:

// Toggle between terminal and editor focus
{
    "key":     "ctrl+`",
    "command": "workbench.action.terminal.focus"
},
{
    "key":     "ctrl+`",
    "command": "workbench.action.focusActiveEditorGroup",
    "when":    "terminalFocus"
}

With these shortcuts you can focus between the editor and the Integrated Terminal using the same keystroke.


NOTE

The key combination suggested here is now built into VSCode as a default (as of 1.72.2, maybe earlier) . See if ctrl + ` works before attempting to add it.

NOTE

In modern versions of VS Code (as of 2022) the Default Keyboard Shortcuts (JSON) file is read-only, so that is why for the custom settings you need to edit a separate dedicated file keybindings.json.

More info can be found on the official Visual Studio documentation page:

39
  • 66
    By far, this is the best answer as the most ergonomically justified solution: extending the existing key binding. Kudos!
    – mloskot
    Commented May 25, 2017 at 15:53
  • 14
    Thanks, this worked fine and saves a lot of time. For users of international keyboards: "ctrl+`" can be specified as "ctrl+oem_3".
    – esel
    Commented Oct 9, 2017 at 12:13
  • 15
    @Roman 1.18.0's behavior is certainly an improvement since when I wrote my answer, but I think the above is still better. The difference is the terminal won't disappear when using the keystroke, only the focus will shift. I happen to like keeping my terminal displayed :)
    – wgj
    Commented Nov 19, 2017 at 6:34
  • 45
    Note that these shortcuts should be pasted to the keybindings.json file. Commented Mar 23, 2018 at 13:44
  • 62
    Open the keybindings.json from the editor: CMD-SHIFT-P -> Preferences: Open Keyboard Shortcuts File. Also a nice resource: code.visualstudio.com/docs/getstarted/keybindings
    – derFunk
    Commented Apr 23, 2018 at 12:53
671

ctrl+` : To Focus on Integrated Terminal

ctrl+1 : To Focus on Editor (If editor-2 command would be ctrl+2)

enter image description here

More Info : https://medium.com/p/21969576c09c

16
  • 28
    where is ` on any keyboard 🙄
    – Ewoks
    Commented Apr 27, 2019 at 11:49
  • 25
    just below esc key :) Commented Apr 28, 2019 at 11:16
  • 12
    Thank you. Ctrl + 1 is what I need, as in some case, ctrl+` will open external terminal and cannot use that again to comeback to VSCode editor Commented May 23, 2019 at 8:58
  • 4
    Control + '~' will work for the toggling between the two. I'm using from quite some time. Commented Jul 31, 2019 at 16:34
  • 6
    @surenderpal ctrl+'~' creates new terminal, it doesn't switch focus to the existing one. Commented Jan 16, 2020 at 11:26
223

Ctrl+J works; but also shows/hides the console.

cmd+J for mac

6
  • 34
    Cmd+J on MacOS.
    – Miscreant
    Commented Apr 20, 2019 at 0:06
  • 4
    Not working in Ubuntu Linux 16.04 (Xenial) + VSC 1.45.0 Commented May 21, 2020 at 10:57
  • 3
    You can use the same hack from the accepted answer as well for cmd+j { "key": "cmd+j", "command": "workbench.action.terminal.focus"}, { "key": "cmd+j", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"} That way I don't have to take my hands off home row.
    – Clintm
    Commented Feb 15, 2021 at 4:17
  • @AldoBassanini Works on Ubuntu 21.04 + VSC 1.57.0
    – Joep
    Commented Jun 14, 2021 at 12:08
  • 2
    Did not know this existed, otherwise I would not have tried the examples above, this should be the accepted answer (MacOS 12.0.1)
    – JVGD
    Commented Dec 13, 2021 at 10:44
82

A little late to the game but I configured mine as the following in the keybindings.json:

{
    "key": "ctrl+`",
    "command": "workbench.action.terminal.focus",
    "when": "editorTextFocus"
},
{
    "key": "ctrl+`",
    "command": "workbench.action.focusActiveEditorGroup",
    "when": "terminalFocus"
},
{
    "key": "alt+`",
    "command": "workbench.action.terminal.toggleTerminal"
}

I wanted separate keys for opening/closing terminal and switching focus back and forth between the windows.

4
  • 6
    Mapping alt+` seems to be buggy - tracked at github.com/Microsoft/vscode/issues/41024#issuecomment-363096692
    – Ben Creasy
    Commented Mar 10, 2018 at 6:24
  • 3
    I found alt easier to press than ctrl, so in my configuration it's the other way round.
    – xji
    Commented Oct 9, 2018 at 17:42
  • This is a great proposal, although I opted for keeping the original bindings and using alt to switch focus. Commented Jan 3, 2019 at 16:43
  • @BenCreasy That's only for macOS, on Windows this works just fine.
    – Kotauskas
    Commented Aug 1, 2019 at 14:43
37

As of version : 1.26.1 (linux), the shortcut is not set by default. To set the shortcut

  1. open keyboard shortcuts panel [ctrl + k , ctrl + s]
  2. Search for Focus Terminal

enter image description here

  1. Set your shortcut

For editor focus is already set by default.

enter image description here

4
  • As they provide additional keyboard mappings, this answer is simpler and faster Commented Oct 24, 2018 at 9:05
  • This focuses the first editor group - might not be what the OP wants. Probably wants the current/active editor group.
    – Mark
    Commented Jan 27, 2020 at 18:39
  • 1
    This is answer for 2020 and anything >= 1.45.0
    – chrismarx
    Commented May 13, 2020 at 21:52
  • Great. Thank you for the clarity here.
    – Fiddy Bux
    Commented May 16, 2020 at 21:58
30

Another option is to use F6 and shift+F6.

F6 does "Focus Next Part", which will move focus from the editor to Panel below (Terminal, Output, Debug Console, etc).

shift+F6 does "Focus Previous Part", which will move focus from Terminal panel back to editor.

The advantage of this over ctrl + ` is that:

  1. It does not hide the Terminal/Panel (if that's what you prefer. If you prefer to hide/unhide the Terminal, then just use ctrl + `).

  2. This will work with any of the Panels (Terminal, Output, Debug Console, etc).

26

I configured mine as following since I found ctrl+` is a bit hard to press.

{
  "key": "ctrl+k",
  "command": "workbench.action.focusActiveEditorGroup",
  "when": "terminalFocus"
},
{
  "key": "ctrl+j",
  "command": "workbench.action.terminal.focus",
  "when": "!terminalFocus"
}

I also configured the following to move between editor group.

{
  "key": "ctrl+h",
  "command": "workbench.action.focusPreviousGroup",
  "when": "!terminalFocus"
},
{
  "key": "ctrl+l",
  "command": "workbench.action.focusNextGroup",
  "when": "!terminalFocus"
}

By the way, I configured Caps Lock to ctrl on Mac from the System Preferences => keyboard =>Modifier Keys.

14

Try using ctrl+` to toggles the visibility of the terminal and as a result toggle the focus.

0
14

Hey my steps to make this work were:

  1. ctrl + shift+ p and look for preferences: keyboard shortcuts

or you can use ctrl k + ctrl s to open it directly

  1. Look in the search box for Terminal: Focus Terminal, I set up for myself alt + T alt + T but you can select the combination that you want

  2. Look in the search box for View: Focus Active Editor Group, set up for myself alt + E alt + E but again you can select the combination that you want

That's it, I hope this help

1
  • 1
    I matched it with tmux ctrl + a down and ctrl + a up and now I can work like I do in tmux... thanks Commented Jan 17, 2022 at 11:11
13

The default keybinding to toggle the integrated terminal is "Ctrl+`" according to VS Code keyboard shortcuts documentation page. If you don't like that shortcut you can change it in your keybindings file by adding something similar to:

{ "key": "ctrl+l", "command": "workbench.action.terminal.toggleTerminal" }

There does not seem to be a default keybinding for simply focusing the bottom panel. So, if you do not want to toggle the bottom panel, you will need to add something similar to the following to your keybindings file:

{ "key": "ctrl+t", "command": "workbench.action.focusPanel" }
3
  • Perfect, Thanks! I'm looking for the second answer you mentioned. If anyone wondering about the keyboard shortcut to put the focus back to editor then it is: Command + 1 (on Mac)
    – Abhijeet
    Commented Mar 14, 2017 at 22:59
  • 1
    I think focusPanel is for the general region (include things like "Problems", "Output" and "Debug Console". There's also an action specifically for the Integrated Terminal workbench.action.terminal.focus.
    – wgj
    Commented Mar 25, 2017 at 5:18
  • ctrl + 1 on windows will put focus back on the editor if you have used ctrl + ` to focus on the integrated terminal. then just ctrl + either 1 or ` for editor and terminal to go back and forth
    – john-g
    Commented Aug 5, 2023 at 17:44
11

Generally, VS Code uses ctrl+j to open Terminal, so I created a keybinding to switch with ctrl+k combination, like below at keybindings.json:

[    
    {
        "key": "ctrl+k",
        "command": "workbench.action.terminal.focus"
    },
    {
        "key": "ctrl+k",
        "command": "workbench.action.focusActiveEditorGroup",
        "when": "terminalFocus"
    }
]
1
  • 1
    Not exactly. By default ctrl+j just toggles Panel. So if last used Panel view was e.g. 'Problems' you will jump there instead of terminal. Also ctrl+k is widely used as chord beginning so overriding it will break a lot of shortcuts. Commented Aug 6, 2021 at 7:23
11

Here is a way to add your own keybinding for switching focus.

  1. Open your VSCode
  2. Press Ctrl+Shift+P and search for keyboard shortcuts and hit this (Preferences: Open Keyboard shortcuts).
  3. Search for 'focus terminal' in the search panel and find this option (Terminal: Focus on Terminal View) and click on the plus icon.

enter image description here

  1. Enter the shortcut as you like which is not used and hit Enter.
  2. Go to Editor mode and try using your shortcut.
  3. Now hit Alt+Shift+T to go to the terminal.
  4. Want to go back to the editor? Just Hit Ctrl+tab

Tested on Windows 10 machine with VSCode(1.52.1)

8

The answer by Shubham Jain is the best option now using the inbuilt keyboard shortcuts.

I mapped enter image description here

to Ctrl + ;

and remapped enter image description here

to Ctrl + L

This way you can have move focus between terminal and editor, and toggle terminal all in close proximity.

1
  • This solved it for me! Keyboard shortcuts --> Terminal: Focus Terminal (workbench.action.terminal.focus) --> changed the Keybinding to my desired combination. Running on vscode Insiders 1.43.0
    – jeppoo1
    Commented Feb 28, 2020 at 7:34
8

What's working for my 1.56 VS Code is:

Ctrl + ~     to focus on terminal window from editor
Ctrl + 9     to focus back on editor from terminal
7

SIMPLE WINDOWS SOLUTION FOR ANY KEYBOARD LAYOUT (may work for other OS but not tested)

I use a Finnish keyboard so none of the above worked but this should work for all keyboards.

  • Terminal focus: Hover your mouse over the terminal text in the integrated terminal. The shortcut for focusing on the terminal will pop up - mine for example said CTRL+ö.
  • Editor focus: as mentioned above use CTRL+1.
1
  • 1
    Thank you, thank you, thank you! So simple, and so easily overlooked. This is by far the best answer in here. Commented Mar 17, 2021 at 9:57
7

Working Settings:

  1. Open the Command Palette (Ctrl+Shift+P Windows/Linux or ⇧ ⌘ P Mac).

  2. Type "Preferences: Open Keyboard Shortcuts (JSON)" and press Enter.

  3. Add the following entries to the keybindings.json file:

[
    { "key": "alt+right", "command": "workbench.action.terminal.focus"},
    { "key": "alt+left", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}   
]

workbench.action.terminal.focus: To switch from editor to terminal.
workbench.action.focusActiveEditorGroup: To switch from terminal to editor.

6

It's not exactly what is asked, but I found it very useful and related.

If someone wants to change from one terminal to another terminal also open in the integrate terminal panel of Visual Studio, you can search for:

Terminal: Focus Next Terminal

Or add the following key shortcut and do it faster with keyboard combination.

  {
    "key": "alt+cmd+right",
    "command": "workbench.action.terminal.focusNext",
    "when": "terminalFocus"
  },
  {
    "key": "alt+cmd+left",
    "command": "workbench.action.terminal.focusPrevious",
    "when": "terminalFocus"
  },
0
5

For ctrl+` combination to switch between, I tried all of listed answers, but no luck. For those who has similar issue like mine, try the following shortcut within keybindings.json: Tested on VSCode 1.59+

[
{
    "key": "ctrl+oem_8","command": "workbench.action.terminal.focus", "when": "!terminalFocus"
},
{
    "key": "ctrl+oem_8","command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"
}
]

enter image description here

1
  • Using a simple backtick instead of oem_8 works like a champ on OSX. The rest of the rules work brilliantly!
    – brnt
    Commented Jan 2, 2022 at 13:02
4

Actually, in VS Code 1.48.1, there is a toggleTerminal command; I don't know if it was available in previous versions ;) You can utilize it in the keybindings.json file.

This worked for me on Windows, and should also works on Linux.

{
    "key": "ctrl+alt+right",
    "command": "workbench.action.terminal.toggleTerminal",
    "when": "editorTextFocus || terminalFocus"
}
3

Here is my approach, which provides a consistent way of navigating between active terminals as well as jumping between the terminal and editor panes without closing the terminal view. You can try adding this to your keybindings.json directly but I would recommend you go through the keybinding UI (cmd+K cmd+S on a Mac) so you can review/manage conflicts etc.

With this I can use ctrl+x <arrow direction> to navigate to any visible editor or terminal. 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.

cmd-J is still used to hide/show the terminal pane.

    {
        "key": "ctrl+x right",
        "command": "workbench.action.terminal.focusNextPane",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+x left",
        "command": "workbench.action.terminal.focusPreviousPane",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+x ctrl+down",
        "command": "workbench.action.terminal.focusNext",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+x ctrl+up",
        "command": "workbench.action.terminal.focusPrevious",
        "when": "terminalFocus"
    },
    {
        "key": "ctrl+x up",
        "command": "workbench.action.navigateUp"
    },
    {
        "key": "ctrl+x down",
        "command": "workbench.action.navigateDown"
    },
    {
        "key": "ctrl+x left",
        "command": "workbench.action.navigateLeft",
        "when": "!terminalFocus"
    },
    {
        "key": "ctrl+x right",
        "command": "workbench.action.navigateRight",
        "when": "!terminalFocus"
    },
3

My solution:

  • has one key
  • if there's no terminal yet: opens a terminal and focuses on it
  • if the focus is on the terminal: hide the panel and switch back to editor
  • if the focus is on the editor and there's a terminal: unhides the terminal pane and focuses on it
  {
    "key": "ctrl+shift+alt+cmd+t",
    "command": "workbench.action.terminal.new",
    "when": "!terminalIsOpen"
  },
  {
    "key": "ctrl+shift+alt+cmd+t",
    "command": "terminal.focus",
    "when": "terminalIsOpen && !terminalFocus"
  },
  {
    "key": "ctrl+shift+alt+cmd+t",
    "command": "workbench.action.closePanel",
    "when": "terminalIsOpen && terminalFocus"
  }
3
  • works great thx - for me without "alt" -- but it doesn't open on "focused tree path" -- Q) any idea how to do that ? 🤔
    – Bruno
    Commented Dec 22, 2021 at 21:11
  • If you don't need the "alt" I suspect you're on a not-macOS computer. Doesn't really matter for the solution of course. The OP did not ask for opening on "focused tree path". I see two challenges with that. 1) Commands don't take arguments. 2) What is the correct path to open? Maybe look into VSCode's predefined variables and the Multi-Command extension. Let me know if you get that working?
    – Niels Bom
    Commented Dec 28, 2021 at 16:34
  • I am using #macos :-) - you know I have focused some tree item which I select witch arrows - then "enter" is renaming - "cmd + arrow down" is open - but missing me that "open that path in terminal" so I can run commands for that file
    – Bruno
    Commented Dec 29, 2021 at 17:28
3

With the key bindings in your keybindings.json:

  • CTRL+j and CTRL+k shift focus between editors in an editor group and terminal windows in the terimal
  • CTRL+h and CTRL+l shift focus between editor groups including the terminal

(These key bindings should feel particularly natural to vim users. Others may wish to change exchange h/j/k/l for left/down/up/right)

// In an editor group, ctrl+j and ctrl+k jump between editor windows
{ "key": "ctrl+j", "command": "workbench.action.nextEditorInGroup" },
{ "key": "ctrl+k", "command": "workbench.action.previousEditorInGroup" },
// In the terminal, ctrl+j and ctrl+k jump between terminal windows
{
    "key": "ctrl+j",
    "command": "workbench.action.terminal.focusNext",
    "when": "terminalFocus && terminalHasBeenCreated && !terminalEditorFocus || terminalFocus && terminalProcessSupported && !terminalEditorFocus"
},
{
    "key": "ctrl+k",
    "command": "workbench.action.terminal.focusPrevious",
    "when": "terminalFocus && terminalHasBeenCreated && !terminalEditorFocus || terminalFocus && terminalProcessSupported && !terminalEditorFocus"
},
// In the work area, ctrl+j and ctrl+k jump between editor groups
{ "key": "ctrl+h", "command": "workbench.action.focusPreviousGroup" },
{ "key": "ctrl+l", "command": "workbench.action.focusNextGroup" },
// in the first editor group terminal, jump "back" to the terminal (if there is a terminal open)
{
    "key": "ctrl+h",
    "when": " terminalHasBeenCreated && terminalIsOpen && activeEditorGroupIndex == 1",
    "command": "workbench.action.terminal.focus"
},
// in the last editor group terminal, jump "forward" to the terminal (if there is a terminal open)
{
    "key": "ctrl+l",
    "when": "terminalHasBeenCreated && terminalIsOpen && activeEditorGroupLast",
    "command": "workbench.action.terminal.focus"
},
// in the terminal, jump "back" to the last editor group
{
    "key": "ctrl+h",
    "command": "workbench.action.focusLastEditorGroup",
    "when": "terminalFocus"
},
// in the terminal, jump "forward" to the last first group
{
    "key": "ctrl+l",
    "command": "workbench.action.focusFirstEditorGroup",
    "when": "terminalFocus"
},
1
  • I use the Vim extension, Ctrl+wj works for going down to the console, for up I use ctrl+1
    – Spartan
    Commented Apr 15, 2022 at 3:09
3

As of 2023 (VS code 1.83.1), toggling back and forth has been made easy.

Use "Crtl+'" to toggle to the terminal. Pressing "Crtl+'" again will close the terminal window going back to the editor. The terminal will not restart when toggling it again.

You can toggle back and forth without closing the terminal window, however: Press "Crtl+'" to go to the terminal. Press "Crtl+1" to go to the editor.

2

If you're in the terminal Ctrl+' (single quote) hides the terminal and jumps back to the code editor. Hit Ctrl+' again to open the terminal which automatically gets the focus.

0

I did this by going to setting>Keyboard Shortcuts then in the section where it give a search bar type focus terminal and select the option. It will ask to type the combination which you want to set for this action. DO it. As for editor focus type" editor focus" in the search bar and type your desired key. IF you excellently add a key . it can be removed by going to edit jason as mentioned in above comments

0

control + '~' will work for toggling between the two. and '`' is just above the tab button. This shortcut only works in mac.

0

The shortuct changes based on the keyboard layout (QWERTY/QWERTZ/AZERTA etc.)

To find out your shortuct press Ctrl+Shift+P and go to Preferences: Keyboard Shortcuts.

From there search for View:Toggle Terminal

final result

0

You can use

CTRL + ` - to switch from active editor to terminal and

CTRL + 1 - to switch back to editor

-1

ctrl + - also works, it means to go back previous cursor position

Not the answer you're looking for? Browse other questions tagged or ask your own question.