404 Visual Studio Tip: Split Views | Kevin William Pang

Visual Studio Tip: Split Views

There are a couple of ways to get a split view in Visual Studio.  Both are incredible time savers that I use daily.  The first is one that most developers will be aware of, but the second seems to be one that many do not seem to know about.

Viewing Two Files in a Split View

Let's say you have two classes you want to compare side by side:

Move your mouse over the Class1 tab and click and drag to anywhere on the window.  When you let go, Visual Studio will prompt you on whether you wish to open a new horizontal tab group or a new vertical tab group:

As you might expect, a new horizontal tab group will split your screen horizontally, and a new vertical tab group will split your screen vertically.  For most developers, I would say a horizontal split makes more sense so you don't have to scroll to see the end of your lines:

This is a very convenient way to compare and edit files side by side.  I have seen several developers take advantage of this feature and it's a great alternative to switching back and forth via the tabs or keyboard shortcuts.

Viewing the Same File in a Split View

What I haven't seen many developers take advantage of however, is a technique I use nearly as often: splitting the same file in Visual Studio.  Let's say you have a single file that is relatively long:

If you want to compare code from one section of this file to another, normally you would have to set bookmarks or just manually scroll back and forth to see both sections of the code.  However, if you hover your mouse over the region right above the scroll bar, you will notice your mouse icon changes from the pointer to the vertical resize tool:

Now if you click and drag down, you'll get a split view of your current file!

Both sections of the split view are editable and will update each other in real time.  When you're done, simply drag the divider all the way to the top and you're back to the normal view! 

This feature comes in very handy when you have long functions or classes and want to compare sections of the code (e.g. reviewing object instantiation before using the object, looking over similar business logic that you want to mimic, etc.).  This feature is available in Visual Studio 2005 and 2008 (and possibly earlier versions, if anyone can confirm please let me know).


Kevin Pang

Kevin is a software engineer at Google whose programming interests revolve around web development, software architecture, and design. When he's not writing software, he enjoys watching Jeopardy!, playing Magic the Gathering, and wandering around Disneyland.


24 thoughts on “Visual Studio Tip: Split Views

  1. Dude, you can also just double-click the little thingy, instead of dragging it, on the "Viewing the Same File in a Split View". Then you get a perfect 50/50 split of the window. Also, double-click the margin again to hide the split.

    Seriously, this is a bit basic. For the audience of this information you really should link to some "Learn basic Visual Studio"-pages and/or videos.


  2. Kevin, just ignore Pete’s crappy attitude. I’ve been using Visual Studio for years – all the way back to VB6 and I didn’t know about splitting the same code file. I knew about the first one (tab groups), but not the second.

    I appreciate the info.


  3. @LazyCodeSlinger

    I’m glad you found it useful! I had a similar reaction from one of my coworkers the other day, hence why I decided to blog it. :-)

  4. I’m so glad and embarrassed at the same time to find out about this just now.

    I remember I used to complain about VS 2005 not having a split view that other editors have. I’m so wrong.

    Thanks Kevin, your blog is full of useful bits.

  5. Is there any way to split the same file vertically instead of horizontally? On my 15.4" laptop I think I can see more code with less scrolling using two vertical panes instead of two narrow horizontal ones. Any ideas guys?

  6. @Ryan:

    Move the focus to the file that you want to be split. Then select Window->New Window from the menu.

  7. Hi there.
    I have two screens and have visual studio expandet over them. I use Vertical tabs with the form on one and the code on the other.
    I can resize the tabs so they fit a screen each using the mouse.
    Does anybody now a way to resize the tabs using the keyboard?

  8. Hi Mike.
    First go to Tools-Options and expand Environment and select Keyboard.
    In the ‘Show commands containing’ type window.split. Give it at shortcut (like Shift-Alt-S). Use this to add new tab. Type window.nextsplit and make a new shortcut (like Shift-Alt-N) to hop from one pane to the next.

  9. Thank you, in fact I discovered it’s F6 but I had to load "default" key combination instead of "Visual C# 2005" I was using.

    I’m still looking for a key to split/unsplit the code window

Comments are closed.