I'm trying to create my own key shortcut to act as the arrow keys in Visual Studio Code.
When I hit "ctrl-p" it pops up a window that I can navigate. However, when I use my special keybinding, which I've set as
{
"key": "alt+i",
"command": "cursorUp",
"when": "textInputFocus"
}
it does not move up to the next option like pressing the up arrow does.
I'm guessing this is due to having either the wrong command or the wrong "when" for getting the keymap to trigger when that window is open.
Normally in Atom I'd just use the key-binding-resolver, but Visual Studio Code doesn't appear to have that yet.
What is the correct command and "when" to navigate through the panels such as the "ctrl-p" panel in Visual Studio Code?
When you click Ctrl-P you are in the file picker, so you need a command that then moves up and down the filepicker. It took a bit because I thought just searching for the UpArrow bindings would make it obvious. But it did not.
Looking again at what Ctrl-P is bound to revealed another command also bound to Ctrl-P : workbench.action.quickOpenNavigateNextInFilePicker so try:
{
"key": "alt+i",
"command": "workbench.action.quickOpenNavigateNextInFilePicker",
"when": "inFilesPicker && inQuickOpen"
},
{
"key": "ctrl+p",
"command": "-workbench.action.quickOpenNavigateNextInFilePicker",
"when": "inFilesPicker && inQuickOpen"
},
{
"key": "alt+j",
"command": "workbench.action.quickOpenNavigatePreviousInFilePicker",
"when": "inFilesPicker && inQuickOpen"
},
{
"key": "ctrl+shift+p",
"command": "-workbench.action.quickOpenNavigatePreviousInFilePicker",
"when": "inFilesPicker && inQuickOpen"
}
Now choosing Alt-I and Alt-J just happens to avoid the usual Alt key trigger of the menu bar opening items, like Alt-D will open the Debug menu. If you have a conflicting Alt-Something that you wanted to use, you can disable the menu bar Alt behavior with:
// If enabled, the main menus can be opened via Alt-key shortcuts. Disabling mnemonics allows to bind these Alt-key shortcuts to editor commands instead.
"window.enableMenuBarMnemonics": false
I'm trying to figure out if there is a way to set up a key binding to allow a quick switch between the terminal windows I have open in the built in terminal rather than having to click on the drop down selector each time. Does anyone know the command for this when making a personal key binding or where I can see a list of all the possible commands for VSC? Thank you in advance!
If you want something that might feel a bit more fluid than using arbitrary key bindings, you can get Ctrl+Tab and Ctrl+Shift+Tab working for both editor switching and terminal switching.
Open your keybindings file with ctrl+shift+p search for Open Keyboard Shortcuts (JSON). Then add..
{
"key": "ctrl+tab",
"command": "workbench.action.openNextRecentlyUsedEditorInGroup",
"when": "editorFocus"
},
{ "key": "shift+ctrl+tab",
"command": "workbench.action.openPreviousRecentlyUsedEditorInGroup",
"when": "editorFocus"
},
{
"key": "ctrl+tab",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
},
{
"key": "ctrl+shift+tab",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
}
From Microsofts Documentation there is a tip:
Tip: If you use multiple terminals extensively, you can add key
bindings for the focusNext, focusPrevious and kill commands outlined
in the Key Bindings section to allow navigation between them using
only the keyboard.
From here:
Other terminal commands are available and can be bound to your
preferred keyboard shortcuts. They are:
workbench.action.terminal.focus: Focus the terminal. This is like
toggle but focuses the terminal instead of hiding it, if it is
visible.
workbench.action.terminal.focusNext: Focuses the next terminal instance.
workbench.action.terminal.focusPrevious: Focuses the previous terminal instance.
workbench.action.terminal.kill: Remove the current terminal instance.
workbench.action.terminal.runSelectedText: Run the selected text in the terminal instance.
Just assign these shortcuts to your preferred keybindings and you are good to go.
That might not be a solution for jumping directly to a terminal (e.g. like vims gt2) but it certainly is a start.
Edit: Just toyed around and found that you can also focus on a specific terminal. Just add any of these commands to your keybindings.json and you are good to go!
// - workbench.action.terminal.focusAtIndex1
// - workbench.action.terminal.focusAtIndex2
// - workbench.action.terminal.focusAtIndex3
// - workbench.action.terminal.focusAtIndex4
// - workbench.action.terminal.focusAtIndex5
// - workbench.action.terminal.focusAtIndex6
// - workbench.action.terminal.focusAtIndex7
// - workbench.action.terminal.focusAtIndex8
// - workbench.action.terminal.focusAtIndex9
e.g.
{ "key": "yourkeybinding", "command": "workbench.action.terminal.focusAtIndex1"}
Here's the solution I built that works well for me on OSX.
It mimics the same shortcuts used in the editor to open new files (cmd+n) and switch between tabs (cmd+left|right) and the same shortcuts work for terminals when that view is in focus.
Hit cmd+shift+p and type keyboard to find Preferences: Open Keyboard Shortcuts File
Add the following to the keybindings.json file and save it.
{
"key": "cmd+alt+right",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
},
{
"key": "cmd+alt+left",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
},
{
"key": "cmd+n",
"command": "workbench.action.terminal.new",
"when": "terminalFocus"
},
{
"key": "cmd+w",
"command": "workbench.action.terminal.kill",
"when": "terminalFocus"
}
It also does the same for closing terminals (cmd+w)
Based on Haini answer, Add the code below to your keybindings.json
{
"key": "shift+up",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
},
{
"key": "shift+down",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
}
Now, you can switch between terminals using shift + down or shift + up
on mac, β§β[ and β§β] worked for me.
this allows me to switch between different terminal instances when the terminal has focus. i use βj to toggle focus between the terminal and editor.
source:
Navigate between terminal groups using focus next β§β] and focus previous β§β[.
https://code.visualstudio.com/docs/editor/integrated-terminal
As for now it already switches tabs on the editor and terminal, just try ctrl + page up or ctrl + page down.
To switch between terminal you can use below commands
On Mac
cmd + shift + [
cmd + shift + ]
This command will switch between terminal group. To find all commands:
command + shift + p (on mac)
Open keyboard shortcuts
Does anyone know the keyboard shortcut (Mac and Linux) to switch the focus between editor and integrated terminal in Visual Studio Code?
While there are a lot of modal toggles and navigation shortcuts for VS Code, there isn't one specifically for "move from editor to terminal, and back again". However you can compose the two steps by overloading the key and using the when clause.
Solution
You can achieve the desired effect by adding the appropriate settings to the keybindings.json file. Here are the required steps:
Open the Command Palette (Ctrl+Shift+P Windows/Linux or β§ β P Mac).
Type "Preferences: Open Keyboard Shortcuts (JSON)" and press Enter.
Add the following entries to the keybindings.json file:
// Toggle between terminal and editor focus
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus"
},
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
}
With these shortcuts you can focus between the editor and the Integrated Terminal using the same keystroke.
NOTE
The key combination suggested here is now built into VSCode as a default (as of 1.72.2, maybe earlier) . See if ctrl + ` works before attempting to add it.
NOTE
In modern versions of VS Code (as of 2022) the Default Keyboard Shortcuts (JSON) file is read-only, so that is why for the custom settings you need to edit a separate dedicated file keybindings.json.
More info can be found on the official Visual Studio documentation page:
Key Bindings for Visual Studio Code: Advanced customization
ctrl+` : To Focus on Integrated Terminal
ctrl+1 : To Focus on Editor (If editor-2 command would be ctrl+2)
More Info : https://medium.com/p/21969576c09c
Ctrl+J works; but also shows/hides the console.
cmd+J for mac
A little late to the game but I configured mine as the following in the keybindings.json:
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus",
"when": "editorTextFocus"
},
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
},
{
"key": "alt+`",
"command": "workbench.action.terminal.toggleTerminal"
}
I wanted separate keys for opening/closing terminal and switching focus back and forth between the windows.
As of version : 1.26.1 (linux), the shortcut is not set by default.
To set the shortcut
open keyboard shortcuts panel [ctrl + k , ctrl + s]
Search for Focus Terminal
Set your shortcut
For editor focus is already set by default.
I configured mine as following since I found ctrl+` is a bit hard to press.
{
"key": "ctrl+k",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
},
{
"key": "ctrl+j",
"command": "workbench.action.terminal.focus",
"when": "!terminalFocus"
}
I also configured the following to move between editor group.
{
"key": "ctrl+h",
"command": "workbench.action.focusPreviousGroup",
"when": "!terminalFocus"
},
{
"key": "ctrl+l",
"command": "workbench.action.focusNextGroup",
"when": "!terminalFocus"
}
By the way, I configured Caps Lock to ctrl on Mac from the System Preferences => keyboard =>Modifier Keys.
Another option is to use F6 and shift+F6.
F6 does "Focus Next Part", which will move focus from the editor to Panel below (Terminal, Output, Debug Console, etc).
shift+F6 does "Focus Previous Part", which will move focus from Terminal panel back to editor.
The advantage of this over ctrl + ` is that:
It does not hide the Terminal/Panel (if that's what you prefer. If you prefer to hide/unhide the Terminal, then just use ctrl + `).
This will work with any of the Panels (Terminal, Output, Debug Console, etc).
Hey my steps to make this work were:
ctrl + shift+ p and look for preferences: keyboard shortcuts
or you can use ctrl k + ctrl s to open it directly
Look in the search box for Terminal: Focus Terminal, I set up for myself alt + T alt + T but you can select the combination that you want
Look in the search box for View: Focus Active Editor Group, set up for myself alt + E alt + E but again you can select the combination that you want
That's it, I hope this help
The default keybinding to toggle the integrated terminal is "Ctrl+`" according to VS Code keyboard shortcuts documentation page. If you don't like that shortcut you can change it in your keybindings file by adding something similar to:
{ "key": "ctrl+l", "command": "workbench.action.terminal.toggleTerminal" }
There does not seem to be a default keybinding for simply focusing the bottom panel. So, if you do not want to toggle the bottom panel, you will need to add something similar to the following to your keybindings file:
{ "key": "ctrl+t", "command": "workbench.action.focusPanel" }
Try using ctrl+` to toggles the visibility of the terminal and as a result toggle the focus.
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"
}
]
Here is a way to add your own keybinding for switching focus.
Open your VSCode
Press Ctrl+Shift+P and search for keyboard shortcuts and hit this (Preferences: Open Keyboard shortcuts).
Search for 'focus terminal' in the search panel and find this option (Terminal: Focus on Terminal View) and click on the plus icon.
Enter the shortcut as you like which is not used and hit Enter.
Go to Editor mode and try using your shortcut.
Now hit Alt+Shift+T to go to the terminal.
Want to go back to the editor? Just Hit Ctrl+tab
Tested on Windows 10 machine with VSCode(1.52.1)
What's working for my 1.56 VS Code is:
Ctrl + ~ to focus on terminal window from editor
Ctrl + 9 to focus back on editor from terminal
The answer by Shubham Jain is the best option now using the inbuilt keyboard shortcuts.
I mapped
to Ctrl + ;
and remapped
to Ctrl + L
This way you can have move focus between terminal and editor, and toggle terminal all in close proximity.
SIMPLE WINDOWS SOLUTION FOR ANY KEYBOARD LAYOUT (may work for other OS but not tested)
I use a Finnish keyboard so none of the above worked but this should work for all keyboards.
Terminal focus: Hover your mouse over the terminal text in the integrated terminal. The shortcut for focusing on the terminal will pop up - mine for example said CTRL+ΓΆ.
Editor focus: as mentioned above use CTRL+1.
It's not exactly what is asked, but I found it very useful and related.
If someone wants to change from one terminal to another terminal also open in the integrate terminal panel of Visual Studio, you can search for:
Terminal: Focus Next Terminal
Or add the following key shortcut and do it faster with keyboard combination.
{
"key": "alt+cmd+right",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
},
{
"key": "alt+cmd+left",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
},
100% Working Settings...
[
{ "key": "alt+right", "command": "workbench.action.terminal.focus"},
{ "key": "alt+left", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}
]
workbench.action.terminal.focus : To switch from editor to
terminal. workbench.action.focusActiveEditorGroup : To switch
from terminal to editor.
Actually, in VS Code 1.48.1, there is a toggleTerminal command; I don't know if it was available in previous versions ;) You can utilize it in the keybindings.json file.
This worked for me on Windows, and should also works on Linux.
{
"key": "ctrl+alt+right",
"command": "workbench.action.terminal.toggleTerminal",
"when": "editorTextFocus || terminalFocus"
}
For ctrl+` combination to switch between, I tried all of listed answers, but no luck. For those who has similar issue like mine, try the following shortcut within keybindings.json: Tested on VSCode 1.59+
[
{
"key": "ctrl+oem_8","command": "workbench.action.terminal.focus", "when": "!terminalFocus"
},
{
"key": "ctrl+oem_8","command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"
}
]
Here is my approach, which provides a consistent way of navigating between active terminals as well as jumping between the terminal and editor panes without closing the terminal view. You can try adding this to your keybindings.json directly but I would recommend you go through the keybinding UI (cmd+K cmd+S on a Mac) so you can review/manage conflicts etc.
With this I can use ctrl+x <arrow direction> to navigate to any visible editor or terminal. Once the cursor is in the terminal section you can use ctrl+x ctrl+up or ctrl+x ctrl+down to cycle through the active terminals.
cmd-J is still used to hide/show the terminal pane.
{
"key": "ctrl+x right",
"command": "workbench.action.terminal.focusNextPane",
"when": "terminalFocus"
},
{
"key": "ctrl+x left",
"command": "workbench.action.terminal.focusPreviousPane",
"when": "terminalFocus"
},
{
"key": "ctrl+x ctrl+down",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus"
},
{
"key": "ctrl+x ctrl+up",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus"
},
{
"key": "ctrl+x up",
"command": "workbench.action.navigateUp"
},
{
"key": "ctrl+x down",
"command": "workbench.action.navigateDown"
},
{
"key": "ctrl+x left",
"command": "workbench.action.navigateLeft",
"when": "!terminalFocus"
},
{
"key": "ctrl+x right",
"command": "workbench.action.navigateRight",
"when": "!terminalFocus"
},
My solution:
has one key
if there's no terminal yet: opens a terminal and focuses on it
if the focus is on the terminal: hide the panel and switch back to editor
if the focus is on the editor and there's a terminal: unhides the terminal pane and focuses on it
{
"key": "ctrl+shift+alt+cmd+t",
"command": "workbench.action.terminal.new",
"when": "!terminalIsOpen"
},
{
"key": "ctrl+shift+alt+cmd+t",
"command": "terminal.focus",
"when": "terminalIsOpen && !terminalFocus"
},
{
"key": "ctrl+shift+alt+cmd+t",
"command": "workbench.action.closePanel",
"when": "terminalIsOpen && terminalFocus"
}
With the key bindings in your keybindings.json:
CTRL+j and CTRL+k shift focus between editors in an editor group and terminal windows in the terimal
CTRL+h and CTRL+l shift focus between editor groups including the terminal
(These key bindings should feel particularly natural to vim users. Others may wish to change exchange h/j/k/l for left/down/up/right)
// In an editor group, ctrl+j and ctrl+k jump between editor windows
{ "key": "ctrl+j", "command": "workbench.action.nextEditorInGroup" },
{ "key": "ctrl+k", "command": "workbench.action.previousEditorInGroup" },
// In the terminal, ctrl+j and ctrl+k jump between terminal windows
{
"key": "ctrl+j",
"command": "workbench.action.terminal.focusNext",
"when": "terminalFocus && terminalHasBeenCreated && !terminalEditorFocus || terminalFocus && terminalProcessSupported && !terminalEditorFocus"
},
{
"key": "ctrl+k",
"command": "workbench.action.terminal.focusPrevious",
"when": "terminalFocus && terminalHasBeenCreated && !terminalEditorFocus || terminalFocus && terminalProcessSupported && !terminalEditorFocus"
},
// In the work area, ctrl+j and ctrl+k jump between editor groups
{ "key": "ctrl+h", "command": "workbench.action.focusPreviousGroup" },
{ "key": "ctrl+l", "command": "workbench.action.focusNextGroup" },
// in the first editor group terminal, jump "back" to the terminal (if there is a terminal open)
{
"key": "ctrl+h",
"when": " terminalHasBeenCreated && terminalIsOpen && activeEditorGroupIndex == 1",
"command": "workbench.action.terminal.focus"
},
// in the last editor group terminal, jump "forward" to the terminal (if there is a terminal open)
{
"key": "ctrl+l",
"when": "terminalHasBeenCreated && terminalIsOpen && activeEditorGroupLast",
"command": "workbench.action.terminal.focus"
},
// in the terminal, jump "back" to the last editor group
{
"key": "ctrl+h",
"command": "workbench.action.focusLastEditorGroup",
"when": "terminalFocus"
},
// in the terminal, jump "forward" to the last first group
{
"key": "ctrl+l",
"command": "workbench.action.focusFirstEditorGroup",
"when": "terminalFocus"
},
I did this by going to setting>Keyboard Shortcuts then in the section where it give a search bar type focus terminal and select the option. It will ask to type the combination which you want to set for this action. DO it. As for editor focus type" editor focus" in the search bar and type your desired key. IF you excellently add a key . it can be removed by going to edit jason as mentioned in above comments
control + '~' will work for toggling between the two. and '`' is just above the tab button.
This shortcut only works in mac.
The shortuct changes based on the keyboard layout (QWERTY/QWERTZ/AZERTA etc.)
To find out your shortuct press Ctrl+Shift+P and go to Preferences: Keyboard Shortcuts.
From there search for View:Toggle Terminal
ctrl + - also works, it means to go back previous cursor position
When using VSCode on Windows, I can navigate the file explorer and hit Enter on the focused file and the file will open in the editor. On my Mac, however, when I do this, VSCode will open the rename input as follows:
I'm not sure why it does this. Even in other text editors (e.g. Atom), the default behavior is to open the file on Enter. Is there any way to change this behavior so that the file opens on Enter? The only workaround I've found so far is CTRL+Enter, which opens the file in a new pane, but with a 3 pane limit in VSCode, this is quite limiting.
If anyone else comes across this problem, the keyboard shortcut to open a file from the file explorer in VSCode on a Mac is:
CMD+Down
This also works in Finder.
I ended up compiling a few solutions here together to get the following keybinding.json editions (Open via Code > Preferences > Keyboard Shortcuts > keybindings.json):
{
"key": "cmd+enter",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
},
{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
},
{
"key": "enter",
"command": "list.select",
"when": "listFocus && !inputFocus"
}
In version 1.19.2, on the mac I was able to go to keyboard shortcuts (menu bar > code > preferences > keyboard shortcuts), search for "rename," and edit "renameFile" ("When" value is "explorerViewletVisible && filesExplorerFocus && !inputFocus") changing the shortcut to "cmd+enter."
You can also past the following in your keybindings.json (there's a link to it on the keyboard shortcuts page):
{
"key": "cmd+enter",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !inputFocus"
}
Enter now opens the highlighted file in the explorer and ctrl+enter puts it in rename/edit mode.
βEditβ
After I upgraded to 1.21.0 the enter key started functioning as renameFile again. cmd+enter still functioned as renameFile as well. To fix this either go to menu bar > code > preferences > keyboard shortcuts and right-click the offending entry and remove it or add a hyphen/minus sign to the beginning of the command in keybindings.json:
{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
}
On my Mac, simply hitting the Spacebar opens the file for me.
So I ran into this as well, but the keyboard shortcuts that I ended using is to map cmd+enter to rename and removing the renameFile from enter.
{
"key": "cmd+enter",
"command": "renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
},
{
"key": "enter",
"command": "-renameFile",
"when": "explorerViewletVisible && filesExplorerFocus"
}
cmd+down does NOT work for me using VSCode 1.10.2 on Mac 10.10.5.
However, cmd+enter does work for me.
Or if you want to set your own keybinding to open a file from File Explorer, add these lines to your keybindings.json:
// open file from File Explorer
{ "key": "enter", "command": "list.select",
"when": "explorerViewletVisible && filesExplorerFocus" },
(Of course, you can change enter to any key combination you want).
SPACE: open but keep focus on Explorer
(filesExplorer.openFilePreserveFocus command)
CMD+Down: open and
focus the opened file (explorer.openAndPassFocus command)
You can change them in "Code - Preferences - Keyboard Shortcuts":
I tried to remove the shortcut of "Rename", which has the Keybinding of "Enter". Then it opens the file properly when I press "Enter".
For me, I have to do command 0 and then do a command down
This brings me to the explorer and then opens the file I select.
In Atom, I just had to hit enter to open the file, I find this to be a strange behavior. vscode v 1.21.1 on OSX
In preferences:
Code -> Preferences -> Keyboard Shortcuts
Add this to your keybindings.json
{
"key": "ctrl+n",
"command": "workbench.action.files.newFile"
}
within the array that may or may not contain other keybindings you have set.
Save keybindings.json
Then when you navigate to a directory in the file explorer, you can create a new file with ctrl+n
Not sure why the "enter" behavior is different, I am not sure "enter" alone is set in the keybindings on your system or its just defaults to different behaviors based on OS standards...
The good news is, what you are looking for is CTRL+P or CTRL+O
CTRL+P let's you find a file, and CTRL+O should open it (the exact behavior you'd like)
You may also be able to add "Enter" as a possibility for the "workbench.action.files.openFile" command, but not sure if that will break anything if you do.
Try it, or just get used to using CTRL+O on both platforms!
More info:
https://code.visualstudio.com/Docs/customization/keybindings