Skip to content

Instantly share code, notes, and snippets.

@jpoehls
Created March 13, 2012 19:02
Show Gist options
  • Select an option

  • Save jpoehls/2030795 to your computer and use it in GitHub Desktop.

Select an option

Save jpoehls/2030795 to your computer and use it in GitHub Desktop.
Using CTRL+W to close tabs in Visual Studio

In Tools | Options | Keyboard...

  1. Add CTRL+W as a Global shortcut for Window.CloseDocumentWindow
  2. Remove the CTRL+W shortcut for Edit.SelectCurrentWord

The caveat to this is if you are used to using CTRL+W to select the current word. If you do, find another shortcut that works for that.

@travisterrell

travisterrell commented Jan 29, 2018 •

Copy link
Copy Markdown

Edit: SOLVED!

I have tried this so many times, but have not achieved success. Until seeing the comments from 2017 suggesting it still works, I assumed Visual Studio had made some change breaks the functionality.

For some reason, after removing the shortcut to Edit.SelectCurrentWord, and even a different key combination to it, pressing CTRL+W doesn't close the window. It still selects the current word. I have also tried assigning CTRL+W to File.Close, as some other sources suggest, but to no avail. Window.CloseDocumentWindow does function correctly with the default CTRL+F4, as well as with other unassigned key combinations (e.g. CTRL+ALT+SHIFT+])

Does anybody know what could possibly be wrong? Thank you!

Solution:
It was also assigned to other conflicting things (other than Edit.SelectCurrentWord). This seems obvious now, but I assumed a "Global" shortcut would override any other associations. Instead it seems that the global applies in any circumstance that a more specific shortcut isn't defined. (Which does make sense.)

So for anybody else experiencing this problem:

  1. Press CTRL+W as if assigning it to a command. Don't click the Assign button, though.
  2. Look at list of commands under "Shortcut currently used by: "
  3. Search for these individually, and click remove button for the CTRL+W key binding. (Re-assign to something else if desired.)
  4. Rinse and repeat.

Now, the global association made to CTRL+W shall work.

ghost commented Feb 7, 2018

Copy link
Copy Markdown

Thx a lot :)

@CaBarr92

Copy link
Copy Markdown

Works in Visual Studio 2017 with a few few tweaks as travisterrell mention above.

CTRL + W is actually bound to 4 items which all need removing - then it you can set it to Window.CloseDocumentWindow.

The default command for Window.CloseDocumentWindow is CTRL + F4

@marin-bratanov

Copy link
Copy Markdown

Yes, @travisterrell is right, in my VS 2017 it was bound to 4 items by default, so you have to

  1. Remove the following mappings:
    • File.Close
    • Edit.SelectCurrentWord
    • Edit.ExpandSelection
    • Edit.NextKeyTyped
  2. Map Ctrl+W to Window.CloseDocumentWindow

@Erutan409

Copy link
Copy Markdown

Thank you!

@kallebornemark

Copy link
Copy Markdown

Thanks!

@retrodev-org

Copy link
Copy Markdown

7 years after you posted it, yet I've been banging my head against this for years. Thank you.

ghost commented Mar 25, 2019

Copy link
Copy Markdown

@jpoehls - OH MY GOD! Thank you so much for that! I've been screaming for years how to get that to work, CTRL-W was File Close so I removed that and changed Window.CloseDocumentWindow to CTRL-W and it never worked! I was like WTF!!?!?!?! I saw this post, removed the assignment to stupid select word (who doesn't use CTRL+SHIFT+Arrow to select words????) Thank you so much!

@Yeronimo

Yeronimo commented Apr 2, 2019

Copy link
Copy Markdown

@marin-bratanov Saved me further headaches! Thank you

@diogoquintanilha

Copy link
Copy Markdown

thanks!

@john-jay

john-jay commented May 6, 2019

Copy link
Copy Markdown

Mapping scheme: VS Code also works for this.

ghost commented Aug 2, 2019 •

Copy link
Copy Markdown

Posting from the world of tomorrow, where forks are made of lasers and this tip is still invaluable. Here are the steps I used to setup Visual Studio 2019, which should also work for 2015 and 2017:

  1. Using the Visual Studio top menu bar, navigate to "Tools > Options > Environment > Keyboard".
  2. In the “Show commands containing” textbox, type in “Window.CloseDocumentWindow”.
  3. In the “Shortcuts for selected command” section, click the “Remove” button until all existing shortcuts are deleted.
    • NOTE: I removed all of the existing shortcuts because I never use them. If you need them, though, keep them and/or choose a different keyboard shortcut.
  4. Set the “Use new shortcut in” dropdown to “Text Editor”.
  5. Set the “Press shortcut keys” textbox to “Ctrl+W”; click the “Assign” button to apply your changes.
  6. Click the “OK” button to save your changes.

NOTE: For some reason, I still have to use “Ctrl+W” twice to close a given tab. Not a big deal, just kinda weird given that the hotkey only has it registered once.

@ukod

ukod commented Aug 7, 2019

Copy link
Copy Markdown

Brilliant! Thank you a lot!

@vertisan

vertisan commented Sep 2, 2019

Copy link
Copy Markdown

In my VS Code it was command: workbench.action.closeActiveEditor (Linux)

@kintax

kintax commented Sep 5, 2019

Copy link
Copy Markdown

thank you! every time i install VS i forget this and i choose File.Close instead... hair-tearer for sure!

@DBJDBJ

DBJDBJ commented Jan 5, 2020 •

Copy link
Copy Markdown

Imagine the organization which can not assign "CTRL+W" to close the window in their flagship development product for a decade or more. Actually much more than a decade. This is not a snarky comment. I am just amazed users need an non-trivial community effort to solve that.

@Burgyn

Burgyn commented Apr 1, 2020

Copy link
Copy Markdown

thanks

@MarioBinder

Copy link
Copy Markdown

Thanks

@joseprofe

Copy link
Copy Markdown

Godlike

@panospd

panospd commented Jun 16, 2021

Copy link
Copy Markdown

The 2nd bullet did the magic! thanks

@akunaatrium

Copy link
Copy Markdown

First thanks from 2022!

@DanCaprine

Copy link
Copy Markdown

Thanks!

@ugurozturk

Copy link
Copy Markdown

Thanks

@TheNotary

Copy link
Copy Markdown

Thanks

@domingoladron

Copy link
Copy Markdown

For those on Resharper, it appears Ctrl+W is used by a couple commands. In order to get Ctrl+W to close a window, you have to clear the Resharper keyboard settings first.

vs-resharper-ctrl-w

@ricardoschwarz

Copy link
Copy Markdown

thank you

@Nereare

Nereare commented Nov 19, 2022

Copy link
Copy Markdown

Thank you so much! ❤️

@LaurentBartkowski

Copy link
Copy Markdown

Thank you !

@niuage

niuage commented Mar 3, 2024

Copy link
Copy Markdown

Still useful to this day :)

@verdantburrito

verdantburrito commented Jun 20, 2025 •

Copy link
Copy Markdown

Here are the steps I used to configure Visual Studio 2022 to use the Ctrl+W keyboard shortcut to close an active text editor tab:

  1. Using the Visual Studio top menu bar, navigate to "Tools > Options > Environment > Keyboard".

  2. Delete any existing keyboard shortcuts that are already bound to Ctrl+W.

    1. In the “Show commands containing” textbox, type “Edit.NextKeyTyped”.
    2. In the "Shortcuts for selected command" dropdown, verify that "Ctrl + W (VC Accelerator Editor)" is selected.
    3. Click the "Remove" button.
    4. In the “Show commands containing” textbox, type “Edit.SelectCurrentWord”.
    5. In the "Shortcuts for selected command" dropdown, verify that "Ctrl + W (Text Editor)" is selected.
    6. Click the "Remove" button.
  3. Create a new Ctrl+W keyboard shortcut that binds to the Window.CloseDocumentWindow command.

    1. In the “Show commands containing” textbox, type “Window.CloseDocumentWindow”.
    2. In the "Shortcuts for selected command" dropdown, verify that "Ctrl + F4 (Global)" is selected.
    3. In the “Use new shortcut in” dropdown, set the value to “Text Editor”.
    4. Click the “Press shortcut keys” textbox, press the Ctrl+W keys on your keyboard simultaneously.
    5. Click the “Assign” button.
  4. Click the “OK” button to save your changes & close the modal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment