Commit No Bug
Published on

Stop Losing Your Terminal: Smart Keybindings for Seamless VS Code Switching

Authors
  • avatar
    Name
    nikUnique
    Twitter
VS Code with the editor open at the top, displaying JavaScript code, and the terminal panel open at the bottom, showing git commands and output

The Problem

You're deep in your code editor, you need to check something in the terminal, you hit Ctrl+` (backtick - on US/UK keyboards; it's left of 1), to toggle it open, and then when you try to get back to your editor, the terminal hides. Your scroll position is still there, but you have to hit Ctrl+` again to bring it back into view. This cycle is one of the most annoying friction points in VS Code. You end up toggling the terminal on and off repeatedly instead of just switching focus between two visible panels.

The default toggle behavior treats the terminal like an on/off switch rather than a panel you can focus on. It doesn't give you the option to keep the terminal visible while you work in the editor. You're forced to choose: terminal visible or hidden. In this post, I show you how to fix it in under a minute with a simple keybinding configuration.

The Solution: Bidirectional Focus Switching

Here's the configuration you need to add to your VS Code keybindings.json file:

// Press Ctrl + ` → switches focus between editor and terminal
{
  "key": "Ctrl+`",
  "command": "workbench.action.focusFirstEditorGroup",
  "when": "terminalFocus"
},
{
  "key": "Ctrl+`",
  "command": "workbench.action.terminal.focus",
  "when": "!terminalFocus"
}

What this does:

  • When you're in the editor (terminal not focused): Ctrl+` moves focus to the terminal and opens it if hidden
  • When you're in the terminal (terminal focused): Ctrl+` moves focus back to the editor, keeping the terminal open

The terminal stays visible. You just switch focus. No more hiding and showing.

To actually hide the terminal when you want to, use Ctrl+J when you are in the terminal, which is VS Code's built-in keyboard shortcut to toggle the panel visibility.

How to Add This to Your VS Code

Step 1: Open keybindings.json

Click the left-bottom gear (Manage) iconKeyboard Shortcuts. In the Keyboard Shortcuts editor page, click the button at the top-right of that editor pane to open keybindings.json.

Alternatively, press Ctrl+Shift+P (or Cmd+Shift+P on Mac) to open the Command Palette, type Preferences: Open Keyboard Shortcuts (JSON) and select the exact command.

Step 2: Paste the Configuration

Add the two keybinding objects above to your keybindings.json file. Make sure you're adding them inside the JSON array (between the square brackets [ ]), not replacing the entire file. If you have existing keybindings, add a comma after the last entry, then paste these two objects.

If your keybindings.json is empty, the structure should look like this:

[
  {
    "key": "Ctrl+`",
    "command": "workbench.action.focusFirstEditorGroup",
    "when": "terminalFocus"
  },
  {
    "key": "Ctrl+`",
    "command": "workbench.action.terminal.focus",
    "when": "!terminalFocus"
  }
]

Note on conflicts: If Ctrl+` is already bound to another command (often from extensions), VS Code will warn you. In that case, either disable the conflicting keybinding to free up Ctrl+`, or add these two keybindings using a different key combination instead. Just change "key": "Ctrl+`" to your chosen binding in both objects.

Step 3: Save and Test

Hit Ctrl+` to test. You should now switch focus between the editor and the terminal without the terminal hiding.

Why This Is Better Than the Default

AspectDefault VS CodeWith These Keybindings
Ctrl+` in editorOpens and hides terminal repeatedlyOpens terminal, focuses it
Ctrl+` in terminalHides terminalReturns to editor, terminal stays open
Workflow interruptionConstant togglingSmooth focus switching
Keyboard flowOpen, work, close, open, closeSwitch, work, switch back

The difference is intent. You're saying "I want to look at the terminal" or "I want to look at my code", not mindlessly toggling a panel on and off.

The Bonus: Use Ctrl+J to Actually Hide It

VS Code's native Ctrl+J shortcut toggles the entire panel visibility. Now your terminal workflow is clear:

  • Ctrl+`: Switch focus between editor and terminal
  • Ctrl+J: Hide/show the entire panel

Keep your terminal open as you work, switch focus between them instantly, and hide it completely only when you're done.

Real-World Workflow

Here's what your development session looks like with this setup:

  1. You're writing code in the editor
  2. You need to run npm test → Press Ctrl+` → terminal opens and focuses
  3. Tests are running, you want to keep editing → Press Ctrl+` → back to editor, terminal still visible
  4. Tests finish, you check results → Press Ctrl+` → terminal is right there
  5. You're done with the terminal → Press Ctrl+J → panel hides entirely

No wasted toggling. No hidden context. Just smooth switching.

Conclusion

This is a tiny configuration change that removes a daily frustration from your VS Code experience. Once you have focus-based switching instead of toggle-based hiding, you'll appreciate this configuration. It's one of those keyboard shortcuts that pays for itself in time saved within the first hour of use.

Copy the keybindings, add them to your config, and enjoy a smoother terminal workflow.

Found this helpful? Please share it with someone who also might find it helpful. Would you like more posts from me? Subscribe to the newsletter. Got questions? Send an email to commitnobug@outlook.com.