Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CtrlCmd+W keybinding to close window when no editors are opened #54492

Closed
graham-sportsmgmt opened this issue Jul 17, 2018 · 72 comments
Closed
Assignees
Labels
feature-request Request for new features or functionality keybindings VS Code keybinding issues verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@graham-sportsmgmt
Copy link

graham-sportsmgmt commented Jul 17, 2018

This could be viewed a duplicate of this Feature Request, but I'm reopening it as a bug for two reasons:

  1. Based on the last comment, I don't believe that the assigned developer completely understood the issue, and
  2. I am adding more specific details that would classify it as a bug.

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:

  1. There are no open Windows, and
  2. The Workspace is not a Window according to the semantics defined in Keyboard Shortcuts.

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 graham-sportsmgmt changed the title [Feature] - Option to only Don't close Workspace when issuing a Close Window keyboard shortcut Jul 17, 2018
@bpasero
Copy link
Member

bpasero commented Jul 17, 2018

@graham-sportsmgmt just add this to your keybindings file and it should be OK:

{
	"key": "ctrl+w",
	"command": "workbench.action.closeActiveEditor"
}

@graham-sportsmgmt
Copy link
Author

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.

@bpasero
Copy link
Member

bpasero commented Jul 18, 2018

@graham-sportsmgmt can you please just do what I said in #54492 (comment) and then see if that fixes your issue and if not we can continue the discussion?

@graham-sportsmgmt
Copy link
Author

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.

@bpasero
Copy link
Member

bpasero commented Jul 18, 2018

@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.

@graham-sportsmgmt
Copy link
Author

It's common for web browsers, but web browsers aren't IDE's.

@bpasero bpasero added feature-request Request for new features or functionality keybindings VS Code keybinding issues labels Jul 18, 2018
@bpasero bpasero changed the title Don't close Workspace when issuing a Close Window keyboard shortcut Remove CtrlCmd+W keybinding to close window when no editors are opened Jul 18, 2018
@orgads
Copy link
Contributor

orgads commented Apr 11, 2019

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.

@kgfly
Copy link

kgfly commented Jul 27, 2019

+1 for default behavior. Current behavior is just annoying.

no one uses vscode as browser, BTW ^_^

@leidegre
Copy link

leidegre commented Oct 1, 2019

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.

@pnavarrc
Copy link

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)

image

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.

@georgyfarniev
Copy link

Hello, this is super annoying I often close my vs code with all running tasks by accidentally press Ctrl+W. A heritage of electron :)

@georgyfarniev
Copy link

See electron/electron#5951

@houh60
Copy link

houh60 commented Dec 17, 2019

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:

  1. go to "settings" (the gear wheel),
  2. then to go "Keyboard Shortcuts",
  3. then type in "ctrl+w",
  4. then select the line (the command would be "Close Window"),
  5. and then press the "delete" key.
  6. done

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.

@LordScree
Copy link

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.

@skupjoe
Copy link

skupjoe commented Jan 6, 2020

+1 that this should be default behavior!

@JayEn84
Copy link

JayEn84 commented Jan 21, 2020

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.

grafik

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.

@y4code
Copy link

y4code commented Jun 4, 2020

remove Eclipse Keymap extension works for me, when i open java project, vscode installed Eclipse Keymap automatically. Don't know why

@tronster
Copy link

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.

@bitwes
Copy link

bitwes commented Nov 11, 2020

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.

@orgads
Copy link
Contributor

orgads commented Nov 12, 2020

According to the release notes, this looks solved. https://code.visualstudio.com/updates/v1_51#_prevent-accidental-close

@tronster
Copy link

@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".

@shakefu
Copy link

shakefu commented Feb 10, 2021

image
In the current version the default behavior is still to close the Workspace Window when you are relentlessly smashing Cmd+W (or Ctrl+W I assume).
It can be changed by removing the "Close Window" keyboard shortcut. There still remains a Cmd+Shift+W shortcut for closing the Workspace Window, which seems fine.
This should really still be the default.

@christhomas
Copy link

This is still a bug in 2021. This issue is so simple, why hasn't it been fixed yet?

@kartikeytewari
Copy link

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.

@nparoski
Copy link

@kartikeytewari solution works like a charm, if you are on windows just change "key":cmd+w" to "key":ctrl+w"

@bpasero
Copy link
Member

bpasero commented Jun 11, 2021

We are suggesting that when no editor is open, and then ANOTHER close command is issued, that the window be closed

But this was exactly the frustration not only a lot of users had but even in the team: when you rapidly close tabs you might accidentally close the entire window because you continued to issue the "Close Editor" command when no editor was opened and that would close the window.

@cmoore1776
Copy link

Windows is certainly inconsistent. Ctrl+W varies from app to app (things like Explorer, Notepad, and web browsers all allow you to close the window when there's nothing left to do).

If people are adamant that the Windows behavior take a "do not close" stance, I can at least understand that because it's case-by-case. But it's unquestionably incorrect behavior on Mac to allow Cmd+W to close tabs but prevent it from closing a window.

@ednl
Copy link

ednl commented Jun 11, 2021

@bpasero:

Did I misunderstand the Apple HIG in this case?

I think so, yes. As I understand it and as I read it, it means that Cmd-W closes one active window, Cmd-Shift-W closes multiple windows (all associated with one document), Opt-Cmd-Shift-W closes all open windows of the app. The latter two seem to be somewhat outdated recommendations back from when apps used to have multi-document interfaces.

I tested this with the single-document interfaces of the Xcode IDE from Apple and the editors Coda and Nova from Panic; all three close documents with Cmd-W, leave the app window open after the last document is closed, then close the app window for another Cmd-W (but not quit the app, which is Cmd-Q).

Also, this is different from Windows and Linux: on MacOS, closing the app window does not quit the app. So the app is still running and active and restoring the window is one more keystroke away (e.g. Cmd-N for new file). As opposed to Windows and Linux where closing the window does quit the app, meaning you'll have to start it up again from the Start Menu or from wherever, possibly involving mouse action.

@bpasero
Copy link
Member

bpasero commented Jun 11, 2021

I tested this with the single-document interfaces of the Xcode IDE from Apple and the editors Coda and Nova from Panic; all three close documents with Cmd-W, leave the app window open after the last document is closed, then close the app window for another Cmd-W (but not quit the app, which is Cmd-Q).

Great, I was about to test that. It makes sense to behave like Xcode here imho. I think we should push a change then for macOS specifically to revert it there. Will investigate as part of our recovery release.

@bpasero
Copy link
Member

bpasero commented Jun 11, 2021

Recovery issue: #126042

@CalumFormby
Copy link

I preferred being able to use ctrl + w to close the application. This is really annoying now. Alt + F4 doesn't really work for me since I have a keyboard which requires you to hold the FN button to be able to use the F keys.

@cmoore1776
Copy link

I preferred being able to use ctrl + w to close the application. This is really annoying now. Alt + F4 doesn't really work for me since I have a keyboard which requires you to hold the FN button to be able to use the F keys.

@CalumFormby you can override the new behavior.

  1. Hit Ctrl+Shift+P to open the command palette.
  2. Search for "Open Keyboard Shortcuts (JSON)"
  3. Paste the following:
[
  {
    "key": "ctrl+w",
    "command": "workbench.action.closeWindow",
    "when": "!editorIsOpen && !multipleEditorGroups"
  }
]

@MartinRJ
Copy link

MartinRJ commented Jun 12, 2021

This was not a valid bug, but a default/standard behaviour. (E.g. in other editors like Notepad.)
Please stop treating feature requests as bugs. This project needs better QA, quite obviously. This is expected behaviour. Not a bug.
VSCode is not an IDE like Visual Studio, but an editor.
It has always worked this way. If you don't agree, get a different editor, or adjust your keyboard shortcuts.

You need to learn to be more careful what keyboard shortcuts you hit, if this is a problem for you.
Everyone had to...

@ryanhiebert
Copy link

Lots of people here are not liking this change, that's understandable, not everyone will be happy. I read this in the changelog, and audibly said "yes! thank you!". Thank you, vscode team!

Closing a workspace is sufficiently different action than closing a window that it should be a different keystroke. Re-opening a workspace is sufficiently more annoying than re-opening a file that this footgun should be avoided by default. I often found myself closing several terminals that I did not want to close, simply for pressing this button one too many times when closing open files.

@CalumFormby
Copy link

@shamelesscookie Awesome, thanks for that :)

@ednl
Copy link

ednl commented Jun 14, 2021

Closing a workspace is sufficiently different action than closing a window that it should be a different keystroke. Re-opening a workspace is sufficiently more annoying than re-opening a file that this footgun should be avoided by default.

@ryanhiebert I can understand having Ctrl-W removed for closing the workspace in Win/Linux because closing the window also quits the app and you have to re-start it, possibly using the mouse. But Cmd-W on Mac works the same in every app: it closes the window but does not quit the app which even remains active. So re-opening it is just another keystroke away (e.g. Cmd-O to open or Cmd-N for new file which in this case only re-opens the window). In any case, it looks like they will leave out Ctrl-W but reinstate Cmd-W in the next update, so that will probably, hopefully, maximise the number of happy people.

Another thing is that you can always, instead of Ctrl/Cmd-W-W-W-W-W-W-W-W-W-W-W-W-W-W, use the long established keyboard shortcut Ctrl/Cmd-K,Ctrl/Cmd-W to close all editors in one go. See Ctrl/Cmd-Shift-P and type "close".

@ryanhiebert
Copy link

So re-opening it is just another keystroke away (e.g. Cmd-O to open or Cmd-N for new file which in this case only re-opens the window).

I am on a Mac. I love my Mac. I really like that closing windows does not close the application.

But closing tabs in bulk should not end in closing my workspace, which is far more than just a collection of tabs. As I mentioned, I regularly run terminals. Sometimes these are environments that are a bit annoying to set up.

It sounds to me like you think command+w should close the workspace. I disagree, but I can make sense of that, from the standpoint of consistency with other applications. I can't make sense of thinking that closing an editor and closing a workspace should share the same keystroke.

Thanks for the cmd k+w hint, I'm glad it exists. Sharing this shortcut between wildly different app-specific contexts is still an obvious footgun that would be wise to avoid, imo. Having a command that doesn't explode your workspace because you pressed the keystroke that closes a single editor still seems like an importantly better user experience to me. Requiring users to avoid common usage patterns because those patterns will make their workspace evaporate unintentionally seems like a less than optimal default experience.

@ednl
Copy link

ednl commented Jun 14, 2021

Sounds to me like you never really use Cmd-W to close a window, only ever to close tabs. If that's the case, I think I may never convince you! Which is fine.

I do think the right decision is to conform to Apple Human Interface guidelines and act the same as any other app on MacOS, also Xcode for instance, and have Cmd-W by default always close the currently active "window" whether that's an editor tab or the workspace window. If you want non-standard behaviour like in this release (i.e. Cmd-W never closes the Vscode window) then you can define that in the settings by adapting #54492 (comment) (I guess it would mean deleting that from the settings? I'm not sure)

@beantowel
Copy link

Now in vscode 1.57.0, Cmd-W can't close an empty window.

@ryanhiebert
Copy link

@ednl: Actually, I do close the window frequently via cmd-w. Sometimes intentionally, sometimes not. I also think that cmd-shift-w being the exclusive way to close the project window entirely is preferable.

I find no particular precedent for how to decide this interface. The HIG guidelines, as far as I can tell, don't say how to handle tabs at all, though it seems likely that I've missed it, since I'd have guessed they would have extended them as they applied them to their own applications that have tabs.

Safari, finder, and others that I can think of are importantly dissimilar to vscode in that closing the final tab in those applications also closes the window. There is no sufficient purpose for keeping the window open once all the tabs have closed in those applications, but that is most certainly not the case in this application. I think you'll agree with that, since I do not think you're advocating that the window itself should be closed along with the final tab.

A precedent worth considering is that the command to close the window is cmd+shift+w (except when the tab and the window are one and the same). You can think of it like "close all tabs", but that is constrained to one window, and importantly, the menu clearly assigns the shortcut to "close window".

That's my reasoning. One final word of caution from me. When you say "the right decision is to conform to Apple Human Interface guidelines", I totally agree. But I haven't found any word about this distinct case, so I must draw on other precedent to find what seems like the most natural application of the principals it has laid out.

We disagree on what is most natural, and that's perfectly okay. I believe the way you're applying the HIG to this case is reasonable, but suboptimal. However, the way your statement about the HIG comes across to me as suggesting that yours is the only possible way to apply the HIG to this situation. While I don't hope to have convinced you that my preference is optimal, I do hope that you understand that unless and until this case is clarified in the HIG, there are indeed other reasonable applications of the HIG than your preference, and that the behavior as implemented is one of them.

@gavinr
Copy link

gavinr commented Jun 15, 2021

How am I supposed to close all tabs in a workspace and the window if I have three files open?

Before this change: Ctrl-W-W-W-W (5 keystrokes)

After this change: Ctrl-W-W-W, Alt-F4 (6 keystrokes plus a hand movment)

Is there a more efficient way?

@uxjw
Copy link

uxjw commented Jun 15, 2021

How am I supposed to close all tabs in a workspace and the window if I have three files open?

Before this change: Ctrl-W-W-W-W (5 keystrokes)

After this change: Ctrl-W-W-W, Alt-F4 (6 keystrokes plus a hand movment)

Is there a more efficient way?

@gavinr On Mac, Shift-CMD-W will now close the window and all its' tabs. Try Shift-Ctrl-W on Windows

@ednl
Copy link

ednl commented Jun 15, 2021

@ryanhiebert Yes, it is my interpretation of the HIG, but I think it is the right one ;) You are right: the HIG hasn't been updated with explicit reference to tabs as used by single-document interface apps (as opposed to what was the norm: multiple separate windows in a multi-document interface). See my earlier comment at #54492 (comment)

I agree on browsers being different. But Xcode and other editors like Panic's Coda and Nova behave like what I think is the norm: close tabs one by one, then close the app window.

@ryanhiebert
Copy link

I agree on browsers being different. But Xcode and other editors like Panic's Coda and Nova behave like what I think is the norm: close tabs one by one, then close the app window.

Xcode at least is significant precedent. After my last comment, I did open Xcode and saw that it worked that way. I think my preference would be better, but 🤷. I'm not familiar with the other editors personally. Good talking with you!

@gavinr
Copy link

gavinr commented Jun 15, 2021

Try Shift-Ctrl-W on Windows

Shift-Ctrl-W closes the window but not the tabs (next time you open the window, the tabs are still open). So using that it's still:


Before this change: Ctrl-W-W-W-W (5 keystrokes)

After this change: Ctrl-W-W-W, Alt-F4 (6 keystrokes plus a hand movment)

  • or:
    • Ctrl-W-W-W, Shift-Ctrl-W (7 keystrokes)

@julian3xl
Copy link

This change is a shame, you've changed the common behaviour we've been using on mac for 30 years

@mxcl
Copy link

mxcl commented Jun 17, 2021

I’m not sure why this is even a discussion, the standard Mac behavior is simple:

  • ⌘W closes tabs
  • ⌘W closes windows
    • If closing the Window would cause something bad to happen, prompt the user with a dialog to confirm they want this

VSCode is a pretty good Mac app, but this decision suggests you should hire a Mac UX person for consultation.

@ednl
Copy link

ednl commented Jun 17, 2021

@julian3xl @mxcl Apparently this is going to be reversed for Mac in the next update, see #54492 (comment)

@merschformann
Copy link

Not a Mac person, but still preferring prior behavior. Thank you for the workaround @shamelesscookie .

@Ulrikop
Copy link

Ulrikop commented Jun 18, 2021

I'm a Linux user and I'm also confused about the new behavior.

especially with multiple opened windows it was good to close just the current window with ctrl + w if no tab was opened and close all windows with ctrl + q

also from me: thanks to @shamelesscookie for the solution

@ryanhiebert
Copy link

If closing the Window would cause something bad to happen, prompt the user with a dialog to confirm they want this

@mxcl @ednl. I think that this suggestion, if implemented well, would alleviate my challenges with the previously existing behavior that prompted this change in the first place. I'm not sure how well vscode can detect whether terminals and other things (perhaps extensions?) that might be important to the user and annoying to recreate are open, but if that could be done reliably, I would drop my objection to ⌘ W closing the project.

I still think that ⇧ ⌘ W would be an excellent shortcut for closing the window and all tabs even if there are terminals and other things open, without the prompt for the user to confirm the action. I'm not sure if it previously worked that way or not (since I'm now using the newer behavior and can't check), but it should. I'd use it now that I know it and have thought about it.

@artdiniz
Copy link

If closing the Window would cause something bad to happen, prompt the user with a dialog to confirm they want this

I really think that's the best UI possible, and that's the reason why I made QuitControl extension. Pressing Enter after Cmd + W to confirm window close and Esc or any other interaction to dismiss it is such a no-brainer. I couldn't live without it 😅

@juliavdkris
Copy link

juliavdkris commented Jun 19, 2021

I feel like this should maybe be an easy setting instead of a keybind that users have to configure themselves (similar to the existing "close when empty" setting)?

In my opinion, CTRL+W to close the window when no tabs are left is the logical thing to do, but I can certainly see why it could be annoying if done unintentionally (never had it happen, but fair enough).

I can also see why people who are annoyed by this would look through the settings first before adding a custom keybind. But changing the default behavior was a bit unnecessary.

And lastly, I really don't think this should've been a bug report. Reopening the linked feature request issue asking for an easy setting is one thing, but this is not a bug. It's a deliberate choice, that (in my opinion) better fits the text editor-like style of VS Code.

 

And thanks to @shamelesscookie for the workaround! I (ironically enough) actually thought this change was a bug on my end lmao

@merschformann
Copy link

FWIW:

To me it seems like prior behavior was also more in line with Ubuntu at least (don't want to generalize for the whole Linux world). gedit, gnome file manager, gnome terminal and of course the browsers close the window with or after closing the last tab.
(for gnome terminal the default key binding is obviously slightly different though - ctrl+shift+w)

I like the behavior for applications which I usually have open in multiple windows with multiple tabs each. ctrl+q does of course not work (as it also closes other windows) and yet another shortcut seems redundant. (this totally is a personal opinion / style of course)

As a former Windows user I understand that these key bindings may not be familiar. Therefore, not sure what the default behavior should be and also not sure whether different behavior on different OS is great (I for one work on multiple platforms). ¯\_(ツ)_/¯
However, it would at least be great to have an easier switch for converting to prior behavior - not only on Mac.
(still thankful for @shamelesscookie's workaround though, so, I am happy =) - but that's not an intuitive solution).

@github-actions github-actions bot locked and limited conversation to collaborators Jun 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality keybindings VS Code keybinding issues verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet