Paragon
Paragon

Reputation: 7371

Open two instances of a file in a single Visual Studio session

I have a file, xyz.cpp. I want to open two instances of this file in Visual studio (BTW, I am using Visual Studio 2005). Why would I want to do so? I want to compare two sections of the same file side by side. I know workarounds such as:

  1. Make a copy of the file. But the problem is that it's not elegant, and I don't want to make copies every time I am faced with this.

  2. I can split the window into two. The problem with split it that I can split it horizontally only. The result of a horizontal split is that the right half of my screen is white space.

If I were able to split it vertically or open two instances of the same file, it would increase the number of lines of code I can compare.

Upvotes: 721

Views: 221718

Answers (15)

user22350513
user22350513

Reputation:

You can just use 'Split'. Goto Windows -> Split

enter image description here

When you are done you may use 'Remove Split'

enter image description here

This can also be achieved by control at the top right corner of you content area.

enter image description here

Upvotes: 0

PaulB
PaulB

Reputation: 24422

Visual Studio

Here's how to do it...

  1. Select the tab you want two copies of
  2. Select menu WindowNew Window from the menu.

enter image description here

  1. Right click the new tab and select New Vertical Tab Group

enter image description here

If New Window is not listed in the *Window menu note that the command does exist, even as of Visual Studio 2017. Add it to the Window menu using menu ToolsCustomizeCommands. At that point decide where to put the New Window command and select Add Command.

VS Code

In Visual Studio Code version 1.25.1 and later

Way 1

You can simply left click on your file in the side-panel (explorer) and press Ctrl + Enter.

Way 2

Simply right click on your file in the Visual Studio Code side-panel (explorer) and select the first option open to the side.

Upvotes: 1153

Taimoor Ahmad
Taimoor Ahmad

Reputation: 559

How to open two instances of the same file side by side in Visual Studio 2019:

  1. Open the file.

  2. Click WindowNew Window.

  3. A new window should be open with the same file.

  4. Click on WindowNew Vertical Document Group.

Result:

Enter image description here

Upvotes: 22

Mani Malekizadeh
Mani Malekizadeh

Reputation: 163

To work on two sections of one long file, simply use a shortcut (Ctrl + \) or click on the split editor window while you are on the selected tab. The icon is on the top-right of the Visual Studio Code.

Enter image description here

Upvotes: 0

Gustavo Rossi Muller
Gustavo Rossi Muller

Reputation: 1142

With the your file opened, go to command window (menu ViewOther WindowsCommand window, or just Ctrl + Alt + A)

Type:

Window.NewWindow

And then

Window.NewVerticalTabGroup

worked for me (Visual Studio 2017).

Or using menus:

Menu WindowNew Window

Menu WindowNew vertical tap group

Upvotes: 14

Kishore Sahasranaman
Kishore Sahasranaman

Reputation: 4230

Go to menuWindowsNew Window:

Enter image description here

Upvotes: 55

user8162574
user8162574

Reputation:

For newer versions (such as Visual Studio 2017)

  • Select the window you want to duplicate.
  • Go to the window tab and click on split at the top of the list.
  • When you are done, click it again to toggle it off.

Upvotes: 4

masih
masih

Reputation: 618

You can use the WindowsNew Window option to duplicate the current window. See more at: Why I like Visual Studio 2010? Undock Windows

Upvotes: 25

mike
mike

Reputation: 1744

When working with Visual Studio 2013 and VB.NET I found that you can quite easily customize the menu and add the "New Window" command - there is no need to mess with the registry!

God only knows why Microsoft chose not to include the command for some languages...?

Upvotes: 4

dumbledad
dumbledad

Reputation: 17525

Luke's answer didn't work for me. The 'New Window' command was already listed in the customize settings, but not showing up in the .js tabs context menu, despite deleting the registry setting.

So I used:

Tools

Customize...

Keyboard...

Scroll down to select Window.NewWindow

And I pressed and assigned the shortcut keys, Ctrl + Shift + W.

That worked for me.

==== EDIT ====

Well, 'worked' was too strong. My keyboard shortcut does indeed open another tab on the same JavaScript file, but rather unhelpfully it does not render the contents; it is just an empty white window! You may have better luck.

Upvotes: 10

Sri
Sri

Reputation:

Open the file (if you are using multiple tab groups, make sure your file is selected).

Menu WindowSplit (alternately, there's this tiny nub just above the editor's vertical scroll bar - grab it and drag down)

This gives you two (horizontal) views of the same file. Beware that any edit-actions will reflect on both views.

Once you are done, grab the splitter and drag it up all the way (or menu WindowRemove Split).

Upvotes: 24

si618
si618

Reputation: 16858

I don't have a copy of Visual Studio 2005, but this process works on Visual Studio 2008:

  1. Open xyz.cpp along with some other file.
  2. Right click on tab header and select new vertical tab group.
  3. Left click on that other file in the first tab group.
  4. Open xyz.cpp through solution explorer again.

You should now have two instances of file in separate vertical tab groups.

Upvotes: 1

Luke Hoffmann
Luke Hoffmann

Reputation: 918

For Visual Basic, HTML and JScript and RDL Expression, the Window > New Window option mentioned in PaulB's answer is disabled. However an option can be changed in the Registry to enable the menu item.

All other languages do not restrict to a single code window so you can use PaulB's answer without editing the registry.

Enabling New Window in Windows Registry.[1] [2]

  1. Go to the following registry key. This example is for Basic (Visual Basic), but the key is also there for HTML, JScript and RDL Expression.

    • 64-bit OS: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Languages\Language Services\Basic
    • 32-bit OS: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Languages\Language Services\Basic
  2. Find the value Single Code Window Only and do one of the following:

    • Set it to 0
    • Rename the value
    • Delete the value (use caution!)

This will enable the "New Window" menu item, but it may still not be visible in the menu.

Adding Menu Item

To actually see the New Window menu item I had to add it back into the menu:

  • Tools > Customize... > Commands > Add Command...
  • Select 'Menu Bar' the select the 'Window' menu in the dropdown
  • Add Command... > Window > New Window > OK

Restoring Registry Value
Copy-paste this to notepad, save as a .reg file and import the file into your registry to restore the initial setting.

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Languages\Language Services\Basic]
"Single Code Window Only"=dword:00000001

Upvotes: 69

Gishu
Gishu

Reputation: 136653

For file types, where the same file can't be opened in a vertical tab group (for example .vb files) you can

  • Open 2 different instances of Visual Studio
  • Open the same file in each instance
  • Resize the IDE windows & place them side by side to achieve your layout.

If you save to disk in one instance though, you'll have to reload the file when you switch to the other. Also if you make edits in both instances, you'll have to resolve on the second save. Visual Studio prompts you in both cases with various options. You'll simplify your life a bit if you edit in only the one instance.

Upvotes: 2

Anton Gogolev
Anton Gogolev

Reputation: 115857

Window menu, New Horizontal/Vertical Tab Group there will do, I think.

Upvotes: 5

Related Questions