Shortcuts & tips from an Impatient DBA
This series of short posts will demonstrate some lesser-known features, keyboard shortcuts, and other tips that make my day as a DBA more productive. None of these are groundbreaking super-secret features–they are the little things that I do as part of my daily work that make me more efficient.
CTRL + W
In all major web browsers, CTRL+W will close your current tab. Muscle memory be damned, CTRL+W doesn’t close the current tab in SSMS. Instead, CTRL+W will select the word at the cursor’s current position. This is still a nice shortcut, but it won’t help you close any windows.
CTRL + F4
Huzzah! This will close your query tab! Easy as pie. Also, note that CTRL+F4 is a pretty universal shortcut that works to close tabs/windows in other applications, too–including your favorite web browser. If you can switch your muscle memory away from CTRL+W to CTRL+F4, you can use that shortcut pretty much everywhere.
But you really want to use CTRL+W (or something else)
If you are willing to sacrifice the “Select current word” default behavior that is tied to CTRL+W, you can re-assign that keystroke to close the query window. Keyboard shortcuts can be mapped in the SSMS Options window. On the navigation tree, go to Environment–>Keyboard–>Keyboard:
- Select “Window.CloseDocumentWindow” from the list. You can type a partial match into the text box to find the item you want.
- Put your cursor in the “Press shortcut keys” text box, type CTRL+W (or whatever else you want), then click “Assign”.
Notice that the “Shortcut currently used by:” drop-down shows that CTRL+W is in use by Edit.SelectCurrentWord. We’ll need to undo that assignment, too.
- Select “Edit.SelectCurrentWord” from the list.
- From the “Shortcuts for selected command” drop-down, you’ll see two items here (assuming you have the out of the box defaults). Select the option for “CTRL+W (Text Editor)” and click “Remove”.
Now, both CTRL+W and CTRL+F4 work to close your query tab!
If you stop after step 2, CTRL+W is assigned to both the select a word, and close tab actions. The result is that SSMS has to choose which action to take. The choice is going to be based on scope. Since the text editor is inside the window you’re closing, the CTRL+W does the “inner most” action…selecting a word. Therefore, we have to do steps 3 & 4 to unassign that “inner” action.