How to quickly close all documents with one click in Visual Studio by adding a custom toolbar button and custom keyboard shortcut

UPDATE: 2/3/2013

In VS 2012 we now have a “Close All Documents” context menu item on the file header. It’s one more click (right click then left click), but still a good option.

ORIGINAL POST:

I blogged about this back in 2007, but I had to set this up again today in Visual Studio 2012 and I realized my other post wasn’t detailed enough.

I often get so many documents open that it is easy to get lost. I always put a “Close All Documents” button in my toolbar and assign a Keyboard shortcut to make closing them much faster than right clicking and selecting Close All But This and then closing the active one.

How to add the Toolbar Button

1. Click the little down arrow on the toolbar that you want to add the button to

2. Click Customize

3. Select Toolbar Standard

4. Click Add Command…

5. Click Workflow in the left hand list box and then click “Close All Documents”, then click OK

6. That will put “Close All Documents” as the first command in the list:

7. Click the Move Down Buttons until it is the last in the list:

How to add the Keyboard Shortcut

1. From the Customize Form click the Keyboard… button right next to the Close button.

2. Type “closeall” into the “Show commands containing” textbox and select “Window.CloseAllDocuments”

3. Click in the Press shortcut keys textbox

4. Hit “CTRL+SHIFT+ALT+D” and then Click the Assign button (You can use a different key combination if you want, I just found this one easy to remember D…for documents.

5. You have now assigned the keyboard shortcut

Hope this saved you some time,

Jon