Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code shortcut to focus integrated terminal

UPDATE: This issue fixed in a later version of VS Code (tested 1.41.1) control + ` works for both opening and focusing events

How to focus to the integrated terminal while it is showing?

https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf

There's a shortcut to show the integrated terminal. But that will hide the terminal if it's already open. It would be nice if there's a shortcut to focus on terminal while typing on editor.

like image 794
Gihan Avatar asked Apr 06 '17 12:04

Gihan


People also ask

What is the shortcut for the terminal in VS Code?

To open the terminal: Use the Ctrl+` keyboard shortcut with the backtick character. Use the View > Terminal menu command. From the Command Palette (Ctrl+Shift+P), use the View: Toggle Terminal command.

What is Ctrl Shift P in VS Code?

You can define a keyboard shortcut for any task. From the Command Palette (Ctrl+Shift+P), select Preferences: Open Keyboard Shortcuts File, bind the desired shortcut to the workbench.

What does Ctrl d do in VS Code?

Ctrl+D selects the word at the cursor, or the next occurrence of the current selection. Tip: You can also add more cursors with Ctrl+Shift+L, which will add a selection at each occurrence of the current selected text.


3 Answers

What you are looking for is the Terminal: Focus Terminal command. By default it's not assigned to a shortcut but you can easily do this using the keyboard shortcut preferences.

You can also call it from the Command Palette by pressing the F1 and typing Focus Terminal.

Keep in mind that this command will also create a new integrated terminal window if one is not already active.

enter image description here

To access the keyboard shortcuts preferences, activate the Command Palette by pressing F1 and then type open keyboard shortcuts. To assign new shortcut for a command, press the + symbol visible on the left side of a row. Popup will appear where you should record your desired keys.

like image 170
Jakub Synowiec Avatar answered Oct 10 '22 12:10

Jakub Synowiec


If the terminal is not already displayed, I hit Ctrl+J.

If the terminal is displayed, I hit Ctrl+J twice.

like image 52
Charles Roper Avatar answered Oct 10 '22 14:10

Charles Roper


I have added the following to my keybindings.json file:

{ 
    "key": "ctrl+`",        
    "command": "workbench.action.terminal.focus",
    "when": "editorFocus"
},
{ 
    "key": "ctrl+`",        
    "command": "workbench.action.terminal.focus",
    "when": "explorerViewletFocus"
}

This covers for me the majority of cases: when my Explorer has focus or when an editor has focus, the same key binding will focus on an existing terminal without toggling it.

You can find all the available when clauses in the VSCode KeyBindings documentation.

This doesn't conflict with the same keybinding already in use globally for workbench.action.terminal.toggleTerminal.

like image 11
Ringo De Smet Avatar answered Oct 10 '22 13:10

Ringo De Smet