Switch focus between the Terminal and the Editor in VS Code

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
3 min

banner

# Table of Contents

  1. Switch focus between the Terminal and the Editor in VS Code
  2. Setting a custom keyboard shortcut to focus between terminal and editor
  3. Don't use the Toggle Panel Visibility command

# Switch focus between the Terminal and the Editor in VS Code

To switch focus between the terminal and the editor in VS Code:

On Windows and Linux:

  1. Press Ctrl + ` (backtick) to focus the terminal.
  2. Press Ctrl + 1 to focus the editor.

The ` (backtick) key and 1 are next to one another. The backtick key is right below the Esc key.

On macOS:

  1. Press Ctrl + ` (backtick) to focus the terminal.
  2. Press Cmd + 1 to focus the editor.

The ` (backtick) key and 1 are next to one another.

You can view the Ctrl + ` action in this table in the docs. The command is called Toggle Integrated Terminal.

The Ctrl (or Cmd) + 1 action can be viewed in this table. The command is called Focus into First Editor Group.

There is also a Ctrl + 2 (or Cmd + 2) keyboard shortcut if you want to focus the second editor group when using a split screen.

Here is a short clip that demonstrates how this works.

switch focus terminal editor

# Only pressing the Ctrl + ` (backtick) key combination

If you don't mind closing the terminal view, you can simply press Ctrl + ` (backtick) to toggle the terminal which is much more convenient.

using the toggle terminal command

The Ctrl + ` (backtick) command toggles the integrated terminal.

The first time you press the key combination, it opens the terminal and focuses it.

If you press it again, it closes the terminal and focuses the editor.

Note that it doesn't completely close the terminal, so you don't have to wait for it to initialize every time.

The terminal keeps running in the background, so toggling it is quite fast.

# Setting a custom keyboard shortcut to focus between terminal and editor

If you want to set a custom keyboard shortcut that allows you to switch focus between the terminal and the editor:

  1. Press:
  • Ctrl + Shift + P on Windows and Linux.
  • Command + Shift + P on macOS.
Note: you can also press F1 to open the Command Palette.
  1. Type Keyboard Shortcuts and select Preferences: Open Keyboard Shortcuts.

preferences open keyboard shortcuts

  1. Click on the Open Keyboard Shortcuts (JSON) icon to the left.

open keyboard shortcuts

  1. Add the following object to your keybindings.json file.
keybindings.json
[ // Switch focus between terminal and editor { "key": "ctrl+`", "command": "workbench.action.terminal.focus" }, { "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus" } ]

switch focus terminal and editor custom keyboard shortcut

Note: If you already have keybindings in the file, remove the enclosing square brackets and only add the objects.

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

The first keyboard shortcut is used to focus the terminal and the second uses a when clause to focus the editor when the terminal is focused.

The keyboard shortcuts use the Ctrl + ` (backtick) key combination but you can specify any other key combination.

Here is a short clip that demonstrates how this works.

switch focus terminal editor keyboard shortcut

# Don't use the Toggle Panel Visibility command

There is also a Toggle Panel Visibility command that is bound to the following keyboard shortcut:

  • on Windows and Linux: Ctr + J.
  • on macOS: Cmd + J.

The command toggles the visibility of the bottom panel and focuses it.

toggle panel visibility

However, the command doesn't necessarily focus the terminal.

For example, if you previously had the Problems or Output tab focused, you won't switch focus to the terminal when you press the keyboard shortcut.

issues when using the toggle panel visibility command

On the other hand, the Toggle Integrated Terminal command which is bound to Ctrl + ` (backtick) always focuses the terminal.

I've also written an article on how to switch to the previous/next tab in VS Code.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.