23

According to the comment here: https://github.com/Microsoft/vscode/issues/50671 it's possible to edit this behavior in the keybindings, but provides no instructions for how to do so.

How do I edit the VScode keybindings so that if I press CTRL+W with no open tabs, it doesn't close the editor? It's highly annoying to be trying to close a bunch of tabs and then accidentally close the entire editor.

5 Answers5

33

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.

7

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.

harrymc
  • 498,455
1

I was also having the same issue. Adding this in keybindings.json file helps:

{
      "key": "cmd+w",
      "command": "-workbench.action.closeWindow",
      "when": "!editorIsOpen && !multipleEditorGroups"
}

This will close active editor by cmd+w . But will not close the vscode window when no editor is open.

0

When you use the recent version, 1.43.1, in the keybindings.json user setup:

  1. Press Ctrl + K, Ctrl + S
  2. Type: view close editor to filter the shortcuts
  3. Find item View: close editor with the keybinding Ctrl + W and right-click it.
  4. Select the item Change when expression in the context menu
  5. Type: !editorIsOpen and press Enter
  6. Restart VS Code
Worthwelle
  • 4,816
0

I set the Window: Confirm Before Close option to keyboardOnly