I want to run a command 'Emmet:Go to Matching Pair' with keybinding 'ctrl+m'
'Emmet:Go to matching pair' is exactly what I see on ctrl+shift+P
Here keybind in keybindings.json:
{
"key": "ctrl+m",
"command": "Emmet: Go to Matching Pair",
"when": "editorTextFocus"
}
Error:
command 'Emmet: Go to Matching Pair' not found
How to get the proper id of the command?
You almost got it. However, instead of entering the command name one has to enter the command ID. You get the command ID in the Keyboard Shortcuts view (opened with Ctrl + K, Ctrl + S). Now when you search for your command Emmet: Go to Matching Pair and hover over it the corresponding command ID is shown.
See the screenshot:
Therefore you have to use editor.emmet.action.matchTag instead. So the following will do:
{
"key": "ctrl+m",
"command": "editor.emmet.action.matchTag",
"when": "editorTextFocus"
}
Related
I'm using a Mac.
I have several VSCode windows opened.
I would like to switch between only 2 (last viewed) windows. Does anyone know what is the keyboard shortcut to do so?
I tried command + `, but it went through all the opened VSCode windows one by one. Similarly for option + tab.
I tried control + w, it went through all the opened VSCode window too unless you use up and down keys to select.
Could anyone help?
Solution 1
Command + Shift + [: switch to the previous window
Command + Shift + ]: switch to the next window
These shortcuts allow you to switch between the last two Visual Studio Code windows.
OR
open command pallete CMD+SHIFT+P and search for Window: Focus Next Group or Window: Focus Previous Group commands to switch between the last two Visual Studio Code windows.
Solution 2
Ctrl +1 Focus into Left Editor Group
Ctrl +2 Focus into Side Editor Group
Ctrl +3 Focus into Right Editor Group
Ctrl +K Ctrl+Left Focus into Editor Group on the Left
Ctrl +K Ctrl+Right Focus into Editor Group on the Right
Use Ctrl + PageUp/PageDow to switch between panes.
⌘K ⌘← / ⌘K ⌘→ Focus into previous/next editor group
Solution 3
You have to edit keybindings.json. Use the Command Palette with CMD+SHIFT+P, enter "Preferences: Open Keyboard Shortcuts (JSON)", and hit enter.
Then add to the end of the file:
[
// ...
{
"key": "ctrl+tab",
"command": "workbench.action.focusPreviousGroup"
},
{
"key": "ctrl+tab", // or change custom shortcuts
"command": "workbench.action.focusNextGroup"
}
]
OR
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "f6",
"command": "workbench.action.navigateEditorGroups"
}
]
OR
[
{
"key": "ctrl+tab",
"command": "workbench.action.quickOpenPreviousRecentlyUsedEditor",
"when": "!inEditorsPicker"
}
]
I have the following mapped to alt+tab, in keybindings.json:
{
"key": "alt+tab",
"command": "workbench.action.quickOpenRecent",
"when": "!inRecentFilesPicker"
},
{
"key": "alt+tab",
"command": "workbench.action.quickOpenNavigateNextInRecentFilesPicker",
"when": "inQuickOpen && inRecentFilesPicker"
},
{
"key": "shift+alt+tab",
"command": "workbench.action.quickOpenNavigatePreviousInRecentFilesPicker",
"when": "inQuickOpen && inRecentFilesPicker"
}
I'm trying to add keybindings containing "+" (e.g. "shift"+"+") to a command of an extension on Linux. Apparently when manually adding such a keybinding to a command, it results to the following json structure (checking keybindings.json):
{
"key": "shift+[BracketRight]",
"command": "vscode-command"
}
Executing this keybinding using "shift"+"+" works.
When declaring this exact key to the package.json keybindings section of the extension and running it afterwards, this binding does not have any effect, the command is still not bound to any keybinding.
Other keybindings like "shift"+"-" and "shift"+"0" do work out of the box.
I've also seen "Ctrl"+"]" as keybindings of commands (maybe using other keyboard layouts), but putting in "]" as "[BracketRight]" replacement also had no effect.
On my Windows installation the key for the command seems to be "shift"+"oem_plus", but this is not recognized correctly on Linux.
I've also tried to use other key combinations containing a "+", but none of them resulted in a keybinding with "Extension" as source.
Does anyone know how to reliably bind keybindings containing "+" to an extension command on all platforms (Windows, Linux, Mac)?
There are 2 + keys on my keyboard
Shift+= (in the vicinity of 0)
Numpad Plus
From the doc: Accepted keys
We have to use = and numpad_add in the key binding definition.
The following key bindings work on Windows.
"keybindings": [
{
"command": "myext.regularplus",
"key": "ctrl+shift+alt+=",
"when": "editorTextFocus"
},
{
"command": "myext.numpadplus",
"key": "ctrl+shift+alt+numpad_add",
"when": "editorTextFocus"
}
]
When I do ^R on the terminal to reverse search, I get the following:
(^R) was pressed. Waiting for second key of chord...
How do I fix this? I'm on OS X.
Also see Run recent command as a replacement for reverse search from the v1.70 Release Notes:
When shell integration is enabled, we're aiming run recent command to
be a cross-shell drop in replacement for the shell's reverse search
(kbstyle(Ctrl+R)). There is a new contiguous search mode that is the
default when triggering the command. This behaves like kbstyle(Ctrl+R)
in most shells, with the option of switching back to fuzzy search:
The new inTerminalRunCommandPicker context key is available that
allows setting up a keybinding like kbStyle(Ctrl+R) to go to the next
match. For example, the following keybindings are now a fairly
complete replacement for your shell's reverse search, with
kbstyle(Ctrl+Alt+R) as a fallback to the old behavior:
{ "key": "ctrl+r", "command": "workbench.action.terminal.runRecentCommand", "when": "terminalFocus" },
{ "key": "ctrl+alt+r", "command": "workbench.action.terminal.sendSequence", "args": { "text": "\u0012"/*^R*/ }, "when": "terminalFocus" },
{ "key": "ctrl+r", "command": "workbench.action.quickOpenNavigateNextInViewPicker", "when": "inQuickOpen && inTerminalRunCommandPicker" },
{ "key": "ctrl+c", "command": "workbench.action.closeQuickOpen", "when": "inQuickOpen && inTerminalRunCommandPicker" },
Perhaps you actually want both! Terminal keybindings that are of the form
Ctrl+R Ctrl+something else
that is, keybindings that are chords AND still use
Ctrl+R (a non-chord keybinding) to trigger a reverse search in the terminal.
You can have both - add this keybinding to your keybindings.json:
{
"key": "ctrl+r",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0012" },
"when": "terminalFocus"
},
That sends a "Ctrl+R" to the terminal and thus starts a reverse search. Even if you have other terminal keychords that starts with Ctrl+R, the terminal will not wait for the second part of a keybinding.
Note if you have a frequently used search you can add text to the command like:
"args": { "text": "\u0012node" },
where it will already have started the search for commands with node in them.
I realized that this started happening with me after I installed "Visual Studio Keymap" extension.
That is how I solved:
Ctrl + Shift + P for the command. There write: "Settings JSON" and select the option that says "Preferences: Open Settings (JSON)"
There, write the following setting:
"terminal.integrated.allowChords": false
Save and be happy
The setting that fixed it for me:
"terminal.integrated.sendKeybindingsToShell": true
When you make a clean vscode install, there will be a popup that explains what is going on with editor and terminal shortcuts. There you can configure your settings.
I used this when I had your same problem. It should work for OS X since it's just about key bindings.
I'm trying to add a new command for "Control C" on the integrated terminal but for some reason It just work when the terminal is not focused.
Here's the configuration:
{
"key": "shift+backspace",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "\u0003" },
}
I've also tried to remove the default command for "shift+backspace"
{
"key": "shift+backspace",
"command": "-deleteLeft",
"when": "textInputFocus && !editorReadonly"
}
Any ideas why it doesn't work?
The issue is that the integrated terminal "consumes" many keystrokes (like ctrl-c) preventing them from being used for keybindings since they are never passed to VScode when the integrated terminal has focus.
Basically, bind the key(s) you want to the desired command, like (in keybindings.json or using the keyboard short cut editor)
...
{
"key": "ctrl-x o",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
},
...
Then add the COMMAND (workbench.action.focusActiveEditorGroup here) to the setting Commands To Skip Shell. In this example, ctrl-x would not be passed to the terminal after this. (What does ctrl-x do, anyway? ) Note that this can remove the ability to send signals to the integrated terminal.
See the setting Terminal › Integrated: Commands To Skip Shell and the documentation at https://code.visualstudio.com/docs/editor/integrated-terminal#_forcing-key-bindings-to-pass-through-the-terminal for more information.
Some keychords seem to be consumed by vscode and never get to the terminal. I haven't been able to figure out which ones. I couldn't get Shift-backspace to work either, but other keychords do such as the following:
{
"key": "ctrl+shift+c",
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "\u0003"
},
}
Perhaps you are ultimately trying to do something like terminate a process with a keybinding?
My most used action is ctrl+b which toggles the sidebars visibility. However when I am focused in the terminal and I press Ctrl + b it types ^B instead of toggling the focus.
I tried add this to my keybindings:
{ "key": "ctrl+b", "command": "workbench.action.toggleSidebarVisibility", "when": "terminalFocus" }
Notice the terminalFocus however it still types the ^B, is it possible to make ctrl+b work when terminal is focused?
The issue is the terminal captures the key input before vscode has a chance to handle it. According the vscode user and workspace settings documentation there is an option to allow certain commands to skip the terminal. You are going to want to add your command to the list of commands to skip the shell:
"terminal.integrated.commandsToSkipShell": [
"workbench.action.toggleSidebarVisibility",
...
],