Visual Studio 2017 Undo-Close Update: The Productivity Power Tools have spun off into a bunch of more-focused extensions. To get Undo Close in Visual Studio 2017, you will want the Power Commands extension now.

Visual Studio 2013 Undo-Close Update: Since the prior options for re-opening closed tabs fell apart with the release of Visual Studio 2013, you will need the newly released Productivity Power Tools 2013.

Update: now with the ability to re-open closed tabs with Ctrl+Shift+T. This also allows you to re-open tabs closed by a project file reload, which is fantastic!

Ever tried to close a tab in Visual Studio 2010/2012 with Ctrl+W. If so, you find yourself selecting the current word in your text editor (Edit.SelectCurrentWord). I don’t use that shortcut, though I could see it being handy over my usual Ctrl+Shift+Right-/Left-Arrow. I do, however, use Ctrl+W to close windows/tabs in just about every other program I use. In order to make that shortcut work for your Visual Studio editing, you just need to assign it to File.Close instead.

For the visual, here’s a snapshot similar to what you will want (note: I already made this change before snapping a pic, so yours may look slightly different).

Visual Studio Keyboard Options

  1. Go into the Tools->Options menu.
  2. Select Environment->Keyboard in that window.
  3. Type “File.Close” in the “Show commands containing” field and select it in the list when it shows.
  4. Choose “Text Editor” for the “Use new shortcut in” field.
  5. In “Press shortcut keys” field, press Ctrl+W.
  6. Click “Assign” to make it happen.
  7. Close the Options window with the “OK” button.

Now, you can happily close windows with Ctrl+W in Visual Studio.

Next step

Figure out how to get Ctrl+Shift+T to bring back the last closed window. If I find a way, I’ll post it.

Update (2012-02-16): Re-open previously closed tabs (with PowerCommands for Visual Studio 2010 [also works for Visual Studio 2012])

As Sergey Vlasov pointed out in a comment, the PowerCommands for Visual Studio 2010 adds the ability to “Undo Close” on previously closed tabs. Since it adds them as commands to Visual Studio, you can also override the default keyboard shortcut (Ctrl+Shift+Z) to a more web-browser-esque shortcut: Ctrl+Shift+T. If you already had this installed for Visual Studio 2010 when you started using Visual Studio 2012, just install the PowerCommands for Visual Studio 2010 again and it will offer to add it to Visual Studio 2012. You will still need to make the shortcut assignment in 2012.

Visual Studio Keyboard Options (Edit.UndoClose)

Just like with your favorite web browser, this will cycle through previously closed tabs, resurrecting them from their graves and restoring your cursor location to right where you left off when you closed them. Amazingly enough, this also works when Visual Studio closes your active windows when a project reloads.


Comments

  • Sergey Vlasov, 2012-02-15 14:23:54 +0000

    PowerCommands extension for Visual Studio 2010 lets you bring back the last closed window: http://visualstudiogallery.msdn.microsoft.com/e5f41ad9-4edc-4912-bca3-91147db95b99/

    “To reopen the most recently closed document, point to the Edit menu, then click Undo Close. Alternately, you can use the Ctrl+Shift+Z shortcut.”

    • Adam Patridge, 2012-02-15 16:21:59 +0000

      Sergey, thanks for tossing that out. That’s a good extension to know. I haven’t given that one a chance, though I do remember hearing about it when someone asked about recursively collapsing projects in the Solution Explorer. There’s a lot to love in that extension (e.g., “Remove and Sort Usings on save”). I appreciate that they make it easy to disable during a presentation, too, if I want to avoid confusing people who may not have it installed (at the risk of looking silly when I try to use its [now disabled] features).

  • Kurt, 2012-08-04 03:55:06 +0000

    Thanks for this. There are a few silly things in VS 2010. Not showing line numbers by default is another…

    • Adam Patridge, 2012-08-24 17:33:11 +0000

      I definitely use line numbers fairly regularly, but that one must not bother me enough to turn it on. If I need a current line number, by default, the cursor’s line number is shown on the IDE status bar (bottom right: “Ln ##”; still there in VS2012). Going the other way, any time I need to find a line by number, I just mash the Ctrl+G shortcut for “Go To…”.

  • Luke Sampson, 2012-08-24 00:37:13 +0000

    Sweet! I tried setting Ctrl-W as a global command but it didn’t work—thanks for the ‘Text Editor’ tip!

    • Adam Patridge, 2012-08-24 17:26:09 +0000

      Glad it helped. I tried that way first, too. There may be window types other than “Text Editor” that wouldn’t allow the shortcut to work this way (maybe some designers or explorer-style windows), but I haven’t found them yet.

  • Hio, 2013-10-26 13:09:57 +0000

    Not working in VS 2013

  • Mike, 2015-07-02 19:53:31 +0000

    Just dropping a quick thanks. That’s been bugging me for a long time now.

  • vijay, 2015-10-02 15:47:26 +0000

    thank you very much! I wish some day all these companies agree to put people before product and use same short cuts for common tasks.

  • Anton Vlasiuk, 2019-02-26 18:00:33 +0000

    Thank you so much! Wonderful tutorial.