Visual Studio 2012 New Features: Preview Tab

 

Preview Tab Overview

We all explore code and need to move quickly between files when examining code to get familiar with it or debugging or [insert file browsing scenario here]. In prior versions of Visual Studio you had to open a file to look at the contents which often resulted in many open files (tabs) when you were done. The Preview Tab eliminates the need to open files when browsing code. Most likely you’ll first encounter the Preview Tab when you are looking at files with Solution Explorer. When you click on a supported file type, you will see the contents of that file in the new preview tab (to the far right in the tab well):

image

 

If you click anywhere inside the file the tab will go from grey to purple to distinguish it from regular (blue) tabs:

image

 

Again, the point of the preview tab is to let you view the contents of a file without actually opening up a new tab in the tab well. As you look at different files the preview tab only shows the contents of the file you are currently on. This keeps the environment from getting cluttered with open tabs and allows you to focus on only those files that are interesting to you. Solution Explorer isn’t the only place you can use the preview feature. It turns up in several situations where you might need to look at file content. For example, when using Find in Files (CTRL + SHIFT + F) to locate information you will see the preview tab:

image

 

 

Promoting Previews

At some point you may decide to promote the preview to an opened tab in the Tab Well so you can do additional work on the file or just keep it around for other purposes. There are a few ways you can make this happen.

 

Click the Keep Open button

Probably the least useful and and least likely technique you will use is to click on the tiny Keep Open button on the Preview Tab.  It’s not only useless it’s actually kind of annoying for some reason I can’t identify:

image

 

Double Click the File

The most likely approach is you will just double click the file in Solution Explorer or whatever results dialog you happen to be in.

 

Press CTRL + ALT + HOME

With the cursor inside the file (the tab is purple) , just press CTRL + ALT + HOME to open a tab for the file you are currently viewing.

 

Change the File

While previewing a file, if you make any change to the file it will automatically be promoted to an open tab so that you can make additional changes and do any other actions you need to perform.

 

Click the Preview Selected Items button

Another button is useless and a waste of space on the Solution Explorer toolbar is the Preview Selected Items button.  You can click it to preview the current file and its only use that I can find is if you turn off single clicking a file to preview it (see below).  Also the tooltip would lead you to believe that you can select multiple files and preview them.  Nope.  Doesn’t work.  Don’t waste your time with this button.

image

 

 

Turning Preview Off

To see the options you have for using the preview feature, just type preview in Quick Launch (CTRL + Q) and click Environment -> Tabs and Windows:

image

 

This will take you to Tools | Options | Environment | Tabs and Windows:

image

 

 

To turn off the preview feature (NOT suggested unless you are having performance issues with it) uncheck the Allow New Files to be Opened in the Preview Tab option. Also notice you can decide if a single click open the files in for preview in Solution Explorer and Find dialogs. For Solution Explorer you can use ALT to prevent a file from being previewed when you click on it. While I see the value in using ALT to prevent preview from happening. I haven’t yet found any reason for turning off the single-click option as it, in effect, forces you to use the Preview Selected Items button which is a lot of extra work and kind of defeats the purpose of the feature.

 

 

Finally

The Preview Tab is one of my top two favorite features in Visual Studio 2012 (the other one being project round-tripping).  You definitely want to leverage this feature to make your life easier.