I like to make connections so I can remember keyboard shortcuts. I get Ctrl+T to open a new tab - but what's the logic behind Ctrl+W to close one?
W in Ctrl+W was chosen because previous to tabbed browsing being introduced (and currently, if you have tabbed browsing disabled) it's a shortcut to Close the Current Window.
Close the current window - Ctrl+W
Close current tab (or the current window if tabbed browsing is disabled) - Ctrl+W
Close tab - Ctrl+W
It was stolen from the Mac OS, which uses Command+W to close the current tab (for applications with tabs) or the current window. Note that Command+Q is used to quit the application, so Command+W, which is one key over, probably seemed like a good choice to close a window.
It was absolutely "stolen" or "borrowed" from Mac OS. Windows originally used Alt+F4 to close windows, but they realized that was a sub-optimal (read: dumb) choice.
W was chosen because of its close proximity to Q which was the obvious choice for a [Q]uit keyboard shortcut.
Apple was very keen on having every piece of software either internally or by a third party follow a set of human interface guidelines. Included in these guidelines was this, among many other things. Microsoft and Windows were much more open to allowing developers to do whatever they chose, and ignoring many conventions, certainly around how keyboard shortcuts worked. I certainly remember a lot of early windows software that had unique cut/copy/paste shortcuts.
For instance, even in Windows 7 Notepad doesn't close with Ctrl+W, you have to use Alt+F4, or Alt, then F, then X.
Another example is the command prompt. Even in 2014, you can't copy and paste like a normal human being, you have to first mark an area of text and then use the enter key to copy it. Likewise to paste, you right click, because why make everything the same? That's boring...
This is the oldest copy I could find of Apple's Human Interface Guidelines. On page 102 it says this:
The Close command closes the active window, which may be a document window, a modeless dialog box, a folder, or any other type of window. Clicking in a window’s close box provides a mouse-based method of closing windows. The user can also press Command-W to close windows.
While this copy of the HIG is from 1995, this convention was on the Mac before even this, perhaps as early as 1986.
There is even this internet gem talking about how Adobe products (on Windows) don't follow the convention used by Firefox:
I like the way Ctrl-W works in Firefox. It closes the current tab, but if there's only one tab open, it closes the whole Firefox window.
In Adobe products, Ctrl-W closes child windows but not the main program window.
Ctrl-W will close Explorer windows, but in many other programs, you have to use some other hotkey. I find myself trying to use Ctrl-W in other programs and getting frustrated when it doesn't work. I know about Alt-F4 but Ctrl-W is an easier combination to reach for.
Would it be possible to make a program that made Ctrl-W always work the way it does in Firefox? That is, no matter what program you were in, Ctrl-W would first close active child windows or tabs, then it would close the main program window. If the program only had one window, it would close that window.
Also, and this part would be optional, would it be possible for this program to:
-detect if the active program has ascribed a different use for Ctrl-W -if the active program uses Ctrl-W for something different, pop up a dialog box asking if you want to override the Ctrl-W behavior for this program from now on (in other words, this would allow the Universal Ctrl-W program to update a "override" and "exceptions" list)?
I hope this sounds useful to other people...
The answers suggesting AutoHotKey and the like are to a Mac user laughingly complex and unnecessary.
There's this as well