I've successfully created a key shortcut for outline.focus which displays the Outline panel. I'm looking for toggle behaviour.
Existing:
{
"key": "ctrl+alt+o",
"command": "outline.focus",
"when": "editorTextFocus"
}
Is it possible??
All keyboard shortcuts in VS Code can be customized via the keybindings.json file. To configure keyboard shortcuts through the JSON file, open Keyboard Shortcuts editor and select the Open Keyboard Shortcuts (JSON) button on the right of the editor title bar.
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.
This will switch focus to the outline view and collapse all opened tree items in the outline view.
[ Handy option: "Follow Cursor" option in the Options View (click the ...
for the options).]
{
"key": "ctrl+alt+o",
"command": "list.collapseAll", // Ctrl+LeftArrow also does this
// Space will open the current tree item
// left/right arrows will open/close item
"when": "outline.active"
},
{
"key": "ctrl+alt+o",
"command": "outline.focus",
"when": "editorTextFocus"
},
So clicking Ctrl+Alt+O once shifts focus to the Outline view and clicking Ctrl+Alt+O a second time collapses all opened items. There is no list.expandAll
command for some reason so you can't toggle those.
These could be combined into a single macro command if you wish, so there would be just one key combo to hit to focus the Outline view and collapse all. Let me know if you want to see that.
With this you should be able to toggle between the outline view and the editor group to the right.
{
"key": "ctrl+alt+o",
"command": "workbench.action.focusRightGroup",
"when": "outline.active"
},
{
"key": "ctrl+alt+o",
"command": "outline.focus",
"when": "editorTextFocus"
,
You can also substitute any of the other focus editor group type of commands, i.e. first group: workbench.action.focusFirstEditorGroup
.
However, you can already do this using the outline focus binding above and then hitting the default editor group binding without defining the toggle.
In addition of outline focus, you also have, with VSCode 1.47, June 2020, the ability to add basic keybinding for focusing on an element in outline panel (PR 91799 for issue 90732)
It will be with the setting list.selectAndPreserveFocus
See:
"Select and keep focus in a list view"
There is a new command,
list.selectAndPreserveFocus
, which lets you select an item from a list, while keeping focus in that list.
This can be helpful if you want to select multiple files from a list, such as the File Explorer, without having focus go to the file editor.The command is not bound to any keyboard shortcut by default, but you can add your own keybinding:
{ "key" : "ctrl+o", "command": "list.selectAndPreserveFocus" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With