Create a shortcut to change focus b/w VS Code editor and terminal

There is no official shortcut assigned in VS code to change the focus between the terminal and the editor, but thanks to the customization options in VS Code you can create a shortcut of your own.

Contents

  • Recollect

  • Procedure

Recollect

Make sure the shortcut which you're assigning is not being used by VS Code natively or by any external extensions you have installed. Overwriting of pre-assigned or native shortcuts might lead to breaking the combination.

Procedure

  1. In VS Code go to File > Preferences > Keyboard Shortcuts
  1. From the top right corner select Open Keyboard Shortcuts (JSON) option

  1. In the keybindings.json file paste the following code inside the square brackets
    [ ] :

     {
             "key": "ctrl+k",
             "command": "workbench.action.terminal.focus"
         },
         {
             "key": "ctrl+k",
             "command": "workbench.action.focusActiveEditorGroup",
             "when": "terminalFocus"
     },
    
  2. If you have not assigned any custom keybindings before, your final code should look something like this:

     [
         {
             "key": "ctrl+k",
             "command": "workbench.action.terminal.focus"
         },
         {
             "key": "ctrl+k",
             "command": "workbench.action.focusActiveEditorGroup",
             "when": "terminalFocus"
         },
     ]
    
  3. Since ctrl+k is generally not a pre-assigned shortcut in VS Code so that's what I am going for, you may assign any key combination of your choice.

  4. Done !

You can now finally use the key combination assigned (here ctrl+k) to change focus between your terminal and your editor or even open a new terminal in case one is not already opened in VS Code.