Is there a way to detect the split/single states of the editor so I can use a single keybinding to split and merge an editor?
{
"key": "ctrl+\\",
"command": "workbench.action.splitEditorDown"
"when": "EDITOR IS IN SINGLE STATE"
},
{
"key": "ctrl+\\",
"command": "workbench.action.editorLayoutSingle",
"when": "EDITOR IS IN SPLIT STATE"
}
Or perhaps there is a different way to set this up?
Thanks.
I think this what you are looking for:
{
"key": "ctrl+\\",
"command": "workbench.action.splitEditorDown",
"when": "!multipleEditorGroups"
},
{
"key": "ctrl+\\",
"command": "workbench.action.editorLayoutSingle",
"when": "multipleEditorGroups"
}
I found that when clause by using the Developer: Inspect Context Keys command.
(1) open the Developer Tools Console: Help/Toggle Developer Tools
(2) run the above command from the Command Palette and click anywhere in an editor
(3) that will create a large object in the Developer Tools Console that has a lot of when context clauses with their current values
(4) do a find in the Console for groups and look for a promising when clause (I first searched with the term split but nothing was helpful).
There is nothing to tell you if a specific file is split into two (or more) groups though - only that there are 1 or more groups of editors.
Related
Until now, I used cmd+2 to split the editor on Visual Studio Code and then cmd+1 and cmd+2 to move between the split editors. This shortcut stopped working for some reason, and I can't set it on the keyboard shortcut menu either.
I checked with another keyboard, so this is not an hardware issue.
Anyhow, I tried to set new keybindings to split the screen and move between the editors, like this:
[
{
"key": "cmd+shift+]",
"command": "workbench.action.navigateRight",
"when": ""
},
{
"key": "cmd+shift+]",
"command": "workbench.action.splitEditorRight",
"when": ""
},
{
"key": "cmd+shift+[",
"command": "workbench.action.navigateLeft",
},
]
The only problem, I couldn't find what I need to write in the when option.
I want my shortcut to split the editor only if the editor is not split yet, and to move between the editors when it is.
How can I achieve that?
The multipleEditorGroups when clause context returns true when there's more than one editor group open.
You don't need to put a "when" for neither of them. Just checked vscode defaults and they don't have any.
In VSCode 1.64.1 on Windows, I'm trying to create some conditional shortcuts for focusing.
When the file explorer is not focused I would like ctrl+0 to focus the active editor group. When the active editor group is focused, I would like ctrl+0 to focus the explorer. I tried the following, but it only partially works.
Currently, hitting ctrl+0 will focus the explorer, but hitting ctrl+0 again when the explorer is focused does not focus the active editor group as desired:
//keybindings.json
{
"key": "ctrl+0",
"command": "workbench.action.focusActiveEditorGroup",
"when": "!editorTextFocus"
},
{
"key": "ctrl+0",
"command": "workbench.action.focusSideBar",
"when": "!explorerFocus"
}
I don't see a explorerFocus context key. The below does work:
{
"key": "ctrl+0",
"command": "workbench.action.focusActiveEditorGroup",
"when": "!editorTextFocus"
},
{
"key": "ctrl+0",
"command": "workbench.action.focusSideBar",
"when": "!filesExplorerFocus" // change here
}
Apparently when you use a non-existent context key that when clause is not evaluated at all - as if it wasn't there. And since evaluation of the keybindings is from the bottom of the file up - first one from bottom wins - your focusActiveEditorGroup command will never be seen.
I would like to have the following feature on VSCode and I don't know if it is possible. For example, if I have this line :
I would like to emphasize this.
I would just select this, clic on a shortcut like ctrl+i and then this appears :
I would like to emphasize {i}this{/i}.
I use a lot of {i} and {/i} tags in my project so this would help me save an incredible amount of time !
I know VSCode already does something similar when you select a word and clic on "
Find your keybindings.json file and insert the following snippet:
{
"key": "ctrl+i",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "{i}$TM_SELECTED_TEXT{/i}"
},
"when": "editorTextFocus && editorHasSelection"
}
Key bindings can be found by pressing Ctrl+Shift+P > type "Keyboard shortcuts", full name being: Open Keyboard Shortcuts (JSON).
I believe that this is not covered by the Preview feature. I simply want to open a file for editing via Quick Open (or any way?) and replace the contents of the active tab, closing the open file and replacing it with the new one.
This behavior is central to the way I edit. Currently, I'm always opening new tabs that I don't want. It's the only barrier left between Code and the way I've used Vim for 15 years. I imagine that this is scriptable, but would like to avoid going down that road. Please tell me I'm missing something.
(1) The drastic approach: search for these in your settings:
Workbench > Editor > Limit: Enabled enable this
Workbench > Editor > Limit: Value set to 1
Drastic, because it will limit you to only 1 editor tab, probably not what you want but it does reuse the active (and only tab) of course.
(2) The macro approach:
Using a macro extension like multi-command put this into your settings.json
"multiCommand.commands": [
{
"command": "multiCommand.openFileInActiveEditor",
"sequence": [
"workbench.action.closeActiveEditor",
"workbench.action.acceptSelectedQuickOpenItem",
"workbench.action.closeQuickOpen" // if you want to close the quickopen panel immediately
]
}
]
and in keybindings.json:
{
"key": "alt+0", // whatever you want
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.openFileInActiveEditor" },
"when": "inFilesPicker && inQuickOpen"
},
It appears that you cannot override the usual right keybinding from the quickOpen panel so I set it to alt+right instead but you can pick whatever you want.
#Mark's answer almost gets you there, but it doesn't work with new (one tab) panes. Here's a modified version of his settings.json edit that does.
Install the multi-command extension
Put this in settings.json
"multiCommand.commands": [
{
"command": "multiCommand.openFileInActiveEditor",
"sequence": [
"workbench.action.acceptSelectedQuickOpenItem",
"workbench.action.previousEditor",
"workbench.action.closeActiveEditor",
"workbench.action.closeQuickOpen"
]
}
]
Put this in keybindings.json and replace the dummy value for the key key with your desired key combination
{
"key": "some+key+combination",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.openFileInActiveEditor" },
"when": "inFilesPicker && inQuickOpen"
},
In chrome and most other browsers/editors, we can go to a particular tab by pressing the Command key and the number. For example: If we press Command+1 we will go to the first tab, Command+2 takes to the second tab, etc.
Is it possible to get such a key mapping for Visual studio code ?
Since VSCode uses ctrl+number by default (which changes desktops in macOS), you can use cmd+number with custom keybindings:
Paste this in your keybindings.user:
{
"key": "cmd+1",
"command": "workbench.action.openEditorAtIndex1"
},
{
"key": "cmd+2",
"command": "workbench.action.openEditorAtIndex2"
},
{
"key": "cmd+3",
"command": "workbench.action.openEditorAtIndex3"
},
{
"key": "cmd+4",
"command": "workbench.action.openEditorAtIndex4"
},
{
"key": "cmd+5",
"command": "workbench.action.openEditorAtIndex5"
},
{
"key": "cmd+6",
"command": "workbench.action.openEditorAtIndex6"
},
{
"key": "cmd+7",
"command": "workbench.action.openEditorAtIndex7"
},
{
"key": "cmd+8",
"command": "workbench.action.openEditorAtIndex8"
},
{
"key": "cmd+9",
"command": "workbench.action.openEditorAtIndex9"
},
This is available now, with the latest version of Visual Studio Code. See: https://github.com/Microsoft/vscode/issues/24753#issuecomment-294518439
On macOS, the shortcuts default to ctrl + n, not cmd + n. You can fix that in Code -> Preferences -> Keyboard Shortcuts.
Another note: most other apps activate the last tab with cmd + 9. You get that behavior by using workbench.action.lastEditorInGroup instead of workbench.action.openEditorAtIndex9.
Unfortunately, no. But you can configure shortcuts to move between tabs, such as going to the previous, next, previously modified, etc. tabs. You can make changes in the Options menu under Keyboard.
This comes standard with the "Emacs Keymap" extension as well as a multitude of other "never touch the mouse" keybindings that I, personally, find keep my stress level way down while navigating code.
Now all I need to find is a way to put the tab's number on the tab itself (which is what I was searching when I found this question).