Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not close the editor window when closing the last tab in VS Code

If there's only one tab on an editor in VS Code, the default behavior is to close the editor right then and there.

Personally, and I think many others agree with me, this behavior is very annoying since the programmer would rather preserve the layout he or she created for the project's workspace.

How do I change this behavior?

I've found discussions on this topic, but all of the solutions do not seem to be the ideal one of simply leaving the editor open but empty. Most of them simply delete the related shortcuts, which seems to me like cutting your arm off just because you broke it.

Anyway, here are some useful links:

  • Superuser StackExchange: How to prevent VScode from closing editor when pressing ctrl+w with no tabs open?
  • Issue #54492: Remove CtrlCmd+W keybinding to close window when no editors are opened
like image 719
Philippe Fanaro Avatar asked Dec 22 '22 16:12

Philippe Fanaro


1 Answers

The behavior of the shortcut ctrl+w is as-designed closing the application

Actually, VSCode 1.57 (May 2021) will change that:

Removed Cmd+W / Ctrl+W as keybinding to close window when no editor is opened

We have gotten feedback that users are frustrated when the window suddenly closes after having closed the last editor via rapid Cmd+W / Ctrl+W usages.

A quick poll in the team also revealed that many had the keybinding for closing a window unassigned, so we went ahead and removed Cmd+W / Ctrl+W as keybinding to close window when no editor is opened.

You can easily bring the keybinding back by configuring it as follows:

{
 "key": "cmd+w", // use "ctrl+w" on windows
 "command": "workbench.action.closeWindow",
 "when": "!editorIsOpen && !multipleEditorGroups"
}

Note: on all platforms there is a dedicated assigned keybinding to close the window:

  • macOS: Cmd+Shift+W
  • Linux: Alt+F4
  • Windows: Alt+F4
like image 114
VonC Avatar answered May 19 '23 12:05

VonC