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).
Enjoyed this post? Share it with others!