This could be viewed a duplicate of this Feature Request, but I'm reopening it as a bug for two reasons:
I frequently use Ctrl + W
to close the active editor. When there are no open Windows (i.e. editor tabs) pressing Ctrl + W
closes the Workspace (i.e. the entire VS Code application) which is not the behavior I want.
In the Keyboard Shortcuts menu there are default bindings for Ctrl + W
to "Close Window" and Ctrl + K + F
to "Close Workspace".
In Version 1.25.1 when there are no open editors, pressing Ctrl + W
(wrongly) assumes that I wanted to issue a Ctrl + K + F
/ Close Workspace command. In this situation the desired behavior is no action as:
This could be fixed by either disabling Close Workspace on Ctrl + W
or adding a configuration option that lets me control the behavior of Ctrl + W
when no editors are open.
@graham-sportsmgmt just add this to your keybindings file and it should be OK:
{
"key": "ctrl+w",
"command": "workbench.action.closeActiveEditor"
}
That's what the default keybindings.json already has:
{ "key": "ctrl+w", "command": "workbench.action.closeActiveEditor" }
Could you please read my post again and let me know which parts need clarification? I'd like to make sure you understand the issue but your comment makes me believe you don't.
@graham-sportsmgmt can you please just do what I said in https://github.com/Microsoft/vscode/issues/54492#issuecomment-405701768 and then see if that fixes your issue and if not we can continue the discussion?
Yes, after adding that line ctrl+w does not close the Workspace.
This bug requests that as the default behavior without needing to edit keybindings.json.
@graham-sportsmgmt but closing the Window when pressing Ctrl+W
is a pretty standard behaviour I would say for applications. And for that reason we make keybindings configurable. I do not think we would change this behaviour.
It's common for web browsers, but web browsers aren't IDE's.
I agree. I hit this bug too often.
Ctrl-W is common for closing a tab or a document in MWI applications, but it is very uncommon for closing the application itself, except browsers which are closed when the last tab is closed. In VS Code there is a preference for that: window.closeWhenEmpty
, but if it is not set I expect the application to just ignore Ctrl-W.
For example, MS Office apps close the active document on Ctrl-W, but they don't quit.
I vote for changing the default behavior.
+1 for default behavior. Current behavior is just annoying.
no one uses vscode as browser, BTW ^_^
The utter insanity och having ctrl+w
close VS Code by default, has to end. It isn't a browser. I know we can configure ourselves out of this situation but common, this is annoying.
I tried setting the keybinding as suggested here without success, editing the keyboard shortcut preferences worked for me though (I just set a shortcut that I won't use)
Maybe there could be a more prominent setting to toggle this behaviour? I'm not sure about what should be the default, but making the setting more accessible would help.
Hello, this is super annoying I often close my vs code with all running tasks by accidentally press Ctrl+W. A heritage of electron :)
Hi "graham-sportsmgmt", the answer is simple. You don't have to CHANGE the command. You just need to DELETE it in the following way:
The above-given way will solve your problem.
I'm like you about that. I use the "ctrl+w" shortcut very, very often. But before, when no files were open, the "ctrl+w" shortcut would close Visual Studio Code completely! I hated that!
So I deleted the whole "Close Window" line. And now the "ctrl+w" shortcut only closes files, not the whole Visual Studio Code, which will stay open as long as you want.
IMO @houh60 has the answer.
I appreciate that @graham-sportsmgmt asked for the _default behaviour_ to be amended, but VSCode is a highly configurable editor.
The simple tweak to the keybindings, as stated by @houh60 resolves this issue. And if you're using an extension like Settings Sync to persist your settings across your different machines, you'll never have to worry about it again.
+1 that this should be default behavior!
I also expected this would be the default behaviour when I switched to VSCode. Thanks @houh60 for sharing his solution. I also deleted the corresponding line, so everything's fine for me now.
(In addition to that, I also deleted the "close window" command for "Ctrl+Shift+W" and then edited the command for closing all editors (originally Ctrol+K+W) to "Ctrl+Shift+W". It's actually the same reason - I'm used to Ctrl+Shift+W from other applications.)
I found this thread on Github after I didn't find any setting inside VSCode and then explicitly searched for a solution here. So before searching here, I opened the VSCode settings (Ctrl+,) and found the "Window" section. Over there, I can decide whether closing the last editor should also close the whole window.
I'm sure I'm not the only one who checked those settings in order to change the Ctrl+W behaviour. Therefore, I would like to propose to extend this setting, so everyone can define their desired behaviour over there as an alternative to changing the default behaviour.
remove Eclipse Keymap
extension works for me, when i open java project, vscode installed Eclipse Keymap
automatically. Don't know why
Echoing what has been said or voted on by many above: please make not closing the application the default behavior with control+W.
It's likely some developers may just live with the behavior and not seek out a solution. (It's been a few months until I decide to search around and see if I could fix this behavior.) There's likely thousands of developers who've come across this thread over the past three years, found the workaround, and left after applying it. But from those who have stuck around to share their thoughts, it looks like there is a strong trend from the community which sees the existing default behavior as more of a hindrance than a help.
For those advocating not changing the default but instead to follow the instructions in remove the closing behavior - the same ease of configuration, that has been expressed, would be true for those who want to configure it back to the current behavior.
An easy win would be to change the default to what the community outlined above. The minority, who want the legacy closing behavior, would just need to reconfigure it to close the APP when no windows are open and CTRL+W is pressed.
Echoing @tronster's echo of all things to be echoed. I also finally got around to googling this after accidentally closing everything too many times. I feel it should be the default behavior.
According to the release notes, this looks solved. https://code.visualstudio.com/updates/v1_51#_prevent-accidental-close
@orgads, that would be great. Taking a look using 1.51 (and then 1.51.1) and it doesn't appear to be in there. Or at least it's not enabled by default and is not a setting in "File > Preferences > Settings".
Most helpful comment
I agree. I hit this bug too often.
Ctrl-W is common for closing a tab or a document in MWI applications, but it is very uncommon for closing the application itself, except browsers which are closed when the last tab is closed. In VS Code there is a preference for that:
window.closeWhenEmpty
, but if it is not set I expect the application to just ignore Ctrl-W.For example, MS Office apps close the active document on Ctrl-W, but they don't quit.
I vote for changing the default behavior.