Closing and Re-opening tabs in Visual Studio with Ctrl+W

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.

Tagged , . Bookmark the permalink.

11 Responses to Closing and Re-opening tabs in Visual Studio with Ctrl+W

  1. PowerCommands extension for Visual Studio 2010 lets you bring back the last closed window:

    “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 says:

      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).

  2. Kurt says:

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

    • 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…”.

  3. Luke Sampson says:

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

    • 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.

  4. Hio says:

    Not working in VS 2013

  5. Mike says:

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

  6. vijay says:

    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.