How to prevent VScode from closing editor when pressing ctrl+w with no tabs open?
Solution 1:
Go to File -> Preferences -> Keyboard Shortcuts (or press Ctrl+K Ctrl+S).
Find the "Close Window" setting with Ctrl+W as the Keybinding.
Right click and remove the key binding or edit it to another combination.
Solution 2:
This is a known bug: #54583 Closing last editor with Ctrl+W closes VS Code (regression), which seems to be a reversion to a previous behavior.
The solution is found in another bug-report:
#53730 User keybindings break if conditions on the default binding change,
which is to edit the file ~/.config/Code/User/keybindings.json
.
Somewhere in the file you should find the following code:
{
"key": "ctrl+w",
"command": "-workbench.action.closeWindow",
"when": "!editorIsOpen"
}
Change the "when" condition so that this looks like:
{
"key": "ctrl+w",
"command": "-workbench.action.closeWindow",
"when": "!editorIsOpen && !multipleEditorGroups"
}
Note that this is marked as fixed, so the bug might be fixed in some upcoming version of VS Code.