140

I just started using VSCode and I'm looking for a way of, while having both the code open and the terminal(the one inside VSCode), switch between typing on these parts of the editor with a shortcut. Looked around the web but the best I could find would be to close and open the terminal.

Any ideas how to do this?

sigmaxf
  • 1,997

16 Answers16

126

I found bit hard to press CTRL+`. It also close the terminal when we press CTRL+'

So, I configured mine as following:

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

Step to configure:

  1. Go to: File > Preferences > keyboard shortcuts
  2. Then in the search-bar, search for focus terminal
  3. Select workbench.action.terminal.focus and then CTRL+k or press your custom key and then press enter.
  4. Similarly, in the search-bar search for focus active editor group
  5. Select workbench.action.focusActiveEditorGroup and then press CTRL+j or press your custom key and then press enter.

After the above setup:

  • Press CTRL+k to focus cursor on terminal
  • Press CTRL+j to focus cursor on coding section without closing terminal
mashuptwice
  • 3,395
40

Refer to this Question/Answers Switch focus between editor and integrated terminal in Visual Studio Code on Stackoverflow, I think @Trav L answer might be closed one. But need to config a little bit more.

VS Code v1.26.1 as a base version

  1. Open keyboard shortcut editor from menu File->Preferences->Keyboard Shortcuts (Ctrl+K Ctrl+S)
  2. Click on the link keybindings.json above the screen.
  3. Overwrite your custom keyboard shortcuts on the right side panel, the keybindings.json file will store in your <user dir>\AppData\Roaming\Code\User. With this values you can overloading the key shortcut with using when keyword like code below.

Credit: @wgj user of Stackoverflow

// Toggle between terminal and editor focus
{ "key": "ctrl+`", "command": "workbench.action.terminal.focus"},
{ "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
  1. Now you can toggle cursor position by press the same key Ctrl+`, VS Code will recognize base by situation where the cursor is.

Special 1

Use Settings Sync extension for saving your custom key binding and others to your secret GIST (Github), for switching between workstation, it's recommended from me. It's quite convenient for me.

Special 2

Some time I need to kill the terminal pane for get the whole code area screen. So I also setting this to keybindings.json. The result is equal to clicking on the X mark of the terminal pane. (Just change to your favorite key if you would like to)

{ "key": "ctrl+k ctrl+`", "command": "workbench.action.terminal.kill" },

16

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"
}]
Felipe Pereira
  • 261
  • 2
  • 4
15

What I like to do is

  • Focus on terminal

    Ctrl+`

  • Focus back to Editor

    Ctrl + E, Enter

8

To switch between the editor and terminal in VS Code (Mac), you can use the following keyboard shortcuts:

Ctrl + ~: To go to the terminal

Ctrl + 1: To go back to the editor

Ctrl + up: To select the editor when the terminal is focused

Ctrl+Shift+P: to open the command palette and search for Focus

7

You do this by setting the keybindings for Focus Terminal and Focus Active Editor Group. These two will allow you to switch the focus between the Editor and the Terminal, without having to just close the terminal.

The other positive is if you perform some action that causes another panel to open such as Output or Problems. Using the keystroke for the editor group will change your focus back to the editor.

I can't say what these are by default because I set this long ago in Code. As you can see from the screenshot below I set them to the same keybinding: ctrl + shift + i.

This makes them act as a toggle switch so it takes the focus back and forth. You can basically just hold down ctrl + shift, then hitting i will move your focus back and forth.

enter image description here

5

Here is how to have the same hotkey to switch back and forth from code to terminal for maximum productivity:

    {
        "key": "f1",
        "command": "workbench.action.focusActiveEditorGroup",
        "when": "terminalFocus"
    },
    {
        "key": "f1",
        "command": "workbench.action.terminal.focusNext",
        "when": "!terminalFocus"
    },
Gaetan
  • 191
  • 1
  • 3
4

If you want Ctrl+` to toggle between terminal and the text editor, then do the following:

  1. Open your keybinding.json file: Ctrl+Shift+P then select Preferences: Open Keyboard Shortcuts (JSON).

  2. Add the following line:

  { "key": "ctrl+`", "command": "workbench.action.terminal.toggleTerminal" },
  1. Save and close keybinding.json file.
TeWu
  • 816
  • 6
  • 6
2

Toggle Integrated Terminal

Ctrl + `

This will turns on/off terminal viewport while switches your cursor back and forth between editor and terminal.

Trav L
  • 466
2

In version 1.86.2 on linux (i dont know whether it is matter) The default keybinding for toggle between the editor, the terminal, and the side bar is F6 and Shift+F6 for reverse toggle.

In more details in the keybinding.json file:

{
  "key": "f6",
  "command": "workbench.action.focusNextPart"
}

{ "key": "shift+f6", "command": "workbench.action.focusPreviousPart" }

Shambre
  • 21
0

I see you already got some options, but I wanted to add the method I use.

Press CTRL + SHIFT + p
Write 'view terminal'
Command palette should now show: View: Toggle Integrated Terminal
Press ENTER

Now you can use CTRL + SHIFT + p followed by ENTER to toggle between terminal and the text editor as long as that command is the last used in the command palette.

This option will hide the terminal when you go back to the editor.

An alternative that only shifts focus and keeps terminal visible is here:

View: Focus First Editor Group
Terminal: Focus Terminal

Also found in the command palette.

I know they are not direct shortcuts, but I find the command palette easy to work with, since I have the commands I often use a few clicks away by using the down arrow.

anders
  • 471
0

There is no default shortcut for switching between terminal and editor in VScode. But you can add USER shortcut in the Settings > Keyboard Shortcuts.

Note:- I have placed "Altr + Ctrl + ," for Editor Focus and "Altr + Ctrl + ." for Terminal Focus as shortcuts, as they are not used by any other tasks and are easy to reach.

In Keyboard Shortcuts, type Focus Active Editor Group and DOUBLE CLICK the option and create your own shortcut and press ENTER.

In Keyboard Shortcuts, type Terminal: focus terminal action and find the option exactly we have written above i.e. "Terminal: focus terminal action" and create your own shortcut and press ENTER

There are many similar options related to terminal focus like previous terminal, next terminal etc but they already have shortcuts, so it would be easy to find it.

Well, i have provided the method for windows, And i am not sure about IOS and LINUX, But I think it will work.

0

answer rolling for April 2021

to focus to your differents panel of VSCode you have to edit your "workbench" commands :

  1. CTRL + K +CTRL +S otherwise Files > Preferences > Keyboard Shortcut

    look for this command

    workbench.action.terminal.focus

    and then add your prefered keybinding for this command vscode zoom on commands

  2. to focus to your code you have to set the following command

    workbench.action.focusActiveEditorGroup

  3. to focus into the file explorer of vscode you have to set the following command

    workbench.files.focusFilesExplorer

and no more need to search to the mouse or to quit your keyboard for the touchpad

That's all folks ! Hope you will spend less energy on your touchpad ... !

marcdahan
  • 101
0

In case that somebody wants to switch between the editor window above and the panel below, regardless of whether the Terminal, the Debug Console, the Output window or the Problem window is opened right now, you can use this code:

{ 
    "key": "ctrl+.", 
    "command": "workbench.action.focusPanel"
},
{ 
    "key": "ctrl+.", 
    "command": "workbench.action.focusActiveEditorGroup", 
    "when": "panelFocus"
}

It took me a bit of trying out until I found that strangely it is focusPanel in the command, but panelFocus in the when-condition.

Note that in my example, I am using "ctrl+.", not "ctrl.+`".

0

Very convenient way to switch between editor and terminal with maximize the window by the default shortcut Ctrl+`

      {
        // disable default rule
        "key": "ctrl+`",
        "command": "-workbench.action.terminal.toggleTerminal",
    },
    {
        // Open the terminal, if wasn't
        "key": "ctrl+`",
        "command": "workbench.action.togglePanel",
        "when": "!terminalIsOpen"
    },
    {
        // Hide the terminal, if editor is active
        "key": "ctrl+`",
        "command": "workbench.action.togglePanel",
        "when": "terminalIsOpen && !terminalFocus"
    },
    {
        // Maximize the terminal, if it's in the focus and editor is opened
        "key": "ctrl+`",
        "command": "runCommands",
        "args": {
            "commands": [
                "workbench.action.toggleMaximizedPanel",
            ]
        },
        "when": "terminalIsOpen && !editorFocus && !panelMaximized"
    },
    {
        // Toggle the terminal and focus on editor, if terminal was maximazed
        "key": "ctrl+`",
        "command": "runCommands",
        "args": {
            "commands": [
                "workbench.action.toggleMaximizedPanel",
                "workbench.action.focusActiveEditorGroup",
            ]
        },
        "when": "terminalIsOpen && !editorFocus && panelMaximized"
    },
0

To switch between the terminal and the code editor in VSCode using a shortcut, this is what I found:

  1. Go to Settings > Preferences > Keyboard Shortcuts.
  2. In the search bar, type workbench.action.terminal.focusAtIndex1.
  3. Assign a shortcut you like to this command.

For reference, I am using VSCode version: 1.91.1 (2024).