All the browsers I know give you the option to close tabs using Ctrl+W in addition to the standard Ctrl+F4 in Windows. I find Ctrl+W easier to reach than Ctrl+F4, but as a developer I switch back and forth between Visual Studio (or VS Code) and my browsers and sometimes by mistake I press Ctrl+W in Visual Studio. That’s why I looked around in Tools > Options to see if there is a way to change this shortcut in Visual Studio once and for all. It was right there waiting for me.
Here is the way to do it:
- Select “Tools > Options” from the menu.
- In the “Options” window look for “Keyboard” under “Environment“.
- In “Show commands containing:” textbox type “Window.CloseDocumentWindow“.
- There’s no surprise that the command is assigned “Ctrl+F4” by default. You need to remove it by clicking “Remove” button in front of “Shortcuts for selected command”. You might need to press a few times if there are more shortcuts assigned to it.
- Make sure “Global” is selected for “Use new shortcut in:“.
- Press “Ctrl+W” in “Press shortcut keys:” box.
- Don’t forget to click “OK” at the end to save your changes.
At the end, you should have something like the following picture.