592

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Paragon
  • 6,081
  • 2
  • 17
  • 8
  • 12
    If you want to just simply compare parts of the file, you could use Window | Split which will split the file horizontally from the middle. – vexe Apr 27 '14 at 22:04
  • @vexe Perfect. Exactly what I needed. Splits windows, both editing the same file. – Vincent P Apr 20 '16 at 06:56
  • 3
    Any reason you haven't accepted the highest-voted answer? – cp.engr Jan 22 '17 at 01:21
  • 2
    @cp.engr, from his profile: "Last seen Dec 6 '09 at 12:41". It's a shame that high rep users cannot mark answers as accepted. – Doctor Jones Nov 27 '18 at 10:55
  • Related post - [Visual Studio: How can I see the same file in two separate tab groups?](https://stackoverflow.com/q/444382/465053) – RBT Feb 25 '21 at 12:50

15 Answers15

953

Here's how to do it...

  1. Select the tab you want two copies of
  2. Select menu WindowNew Window from the menu.
  3. Right click the new tab and select New Vertical Tab Group

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.

UPDATED on "30 July 2018"

In Visual Studio Code version 1.25.1 and later

Way 1

You can simple 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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
PaulB
  • 20,984
  • 13
  • 54
  • 75
  • 50
    If you have some screen space available like a second monitor, you could also drag the new tab out of Visual Studio and see it, for instance, in the second monitor. – Artur Carvalho Nov 23 '10 at 17:46
  • 5
    You can only do this for certain file types ... for example, you can't have two windows open on the same .xaml file. Which is a bummer, cause that's what I want to do! – cplotts Jan 06 '11 at 17:53
  • Also not working for vb files. :-( It seems to depend on the specific editor, whether it's possible or not. – Daniel Hilgarth May 04 '11 at 15:33
  • 1
    @DanielHilgarth See [Luke's answer](http://stackoverflow.com/questions/728949/open-two-instances-of-a-file-in-single-visual-studio-session/7396899#7396899) It enables the feature for VB (in VS 2010 at least). – Jason S Nov 18 '11 at 01:10
  • 4
    @Shlomi.A. Try [Luke's Answer](http://stackoverflow.com/questions/728949/open-two-instances-of-a-file-in-single-visual-studio-session/7396899#7396899) – Jason S Nov 18 '11 at 01:32
  • 1
    Well...you can just click Window -> Split in VS 2012 – TheMentor Nov 27 '12 at 12:36
  • @TheMentor it splits horizontaly :/ And can be splitted only once :/ – jave.web Mar 04 '15 at 12:32
  • @TheMentor - he wants it split vertically – PaulB Mar 26 '15 at 08:21
  • 2
    For XAML in WPF the New Window option is just not there. – Preza8 Jun 04 '15 at 17:14
  • Once you have the two panels: Is it possible to always display open files twice? Meaning: Once you change the displayed file in panel A, then panel B automatically refreshes and shows the same file displayed in panel A and vice versa? – Benj Jun 18 '15 at 11:26
  • 2
    This method works, but on my VS 2010 the shortcut [Ctrl] [Shift] [N] was bound to File > New > Project – user1556435 Feb 20 '16 at 13:20
  • It doesn't work in VS 2015, That menu is disabled. I can split it in horizontally though. http://prntscr.com/d8e9fm – Georgi Kovachev Nov 17 '16 at 11:26
  • @GeorgiKovachev - just tried in VS2015 - works fine for C# files - as mentioned in the comments it's not available for all file types - check out Lukes answer to enable it for your cshtml files – PaulB Nov 17 '16 at 19:08
  • VS 2015 Enterprise Update 1: This works for .js files now – TSmith Dec 22 '16 at 20:08
  • _Select Window > New Window from the menu_ .... ok I am not a native English speaker, but I woudn't have ever guessed that "New Window" would open another instance of the currently active child window. Brilliant! – Andreas Aug 15 '18 at 11:45
  • New Window is absent in VS2017 Version 15.9.3 for C++ (but was perhaps working in earlier VS2017 release??). Had to come here for this simple fix!! – Ravi Ganesh Jan 31 '19 at 06:29
67

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
Community
  • 1
  • 1
Luke Hoffmann
  • 889
  • 8
  • 12
  • No need to edit the registry for C# files as the 'New Window' menu item should be already enabled for C# files (in VS 2010). You only need to do this for VB, HTML or JScript. According to [this MS Connect issue report](https://connect.microsoft.com/VisualStudio/feedback/details/559243/enable-the-windows-new-window-feature-for-visual-basic) any issues with this are fixed for VB, you just need to remove or rename the registry entry to enable the feature. – Jason S Nov 21 '11 at 02:35
  • 1
    This works in Visual Basic 2010 Express as well, I'm happy to report. The registry key is slightly different: [HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VBExpress\10.0\Languages\Language Services\Basic]. – evilspoons Feb 14 '12 at 19:41
  • Doesn't work for me. Tried restarting VS2010, will give it another chance after rebooting computer... (who knows how are registry entries read/stored/updated) – Mars Robertson Mar 27 '12 at 16:14
  • I just tested this (I guess my registry key got overwritten by updates or something). I didn't require a reboot. I changed the key with VS2010 running, 'New Window' still greyed out. Then closed VS2010 and opened VS2010 and 'New Window' is available. – Luke Hoffmann Apr 19 '12 at 01:44
  • The first link in my answer says _"The feature was put in, but not fully tested. So it was disabled."_ After using it for a while I can see why. After a while the menus at the top (the ones that list the class members) stop working properly or are just empty. Does that happen with C#? – Luke Hoffmann Apr 19 '12 at 01:49
  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Languages\Language Services\Basic Editing the RegEdit "Single Code Window Only"=0 sucess! Worked in Visual Studio 2008 Professional. – Ben_Coding Jul 25 '12 at 22:32
  • 3
    In VS2010, flipping the registry bit for JScript does allow a second tab to be opened for a JavaScript file (yay), but nothing except whiteness is rendered in each tab (boo). – G-Wiz May 09 '13 at 22:12
  • NOTE: Don't attempt this hack. Like @gWiz said it doesn't work, and also after changing this my visual studio 2010 started behaving weirdly, displaying files wrong in the splits. I believe the registry flags are there for a reason... – andersand Jun 21 '13 at 09:06
  • @andersand, where you able to revert after things went wrong, or was it a permanent problem? – zod Oct 14 '13 at 14:21
  • My VS is working fine now (at least AFAICT, I'm not using all features, and I do use resharper). I checked my registry now, and I have the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Languages\Language Services\JScript\Single Code Window Only set to 1. – andersand Oct 15 '13 at 08:31
  • why is disabled in the first place? – wotanii Nov 11 '16 at 15:17
  • I can't believe we're still using the same window paradigm we've been using since the 1990s. It's pathetic. I should be able to juggle windows and panels in 3D space, zoom in on, segment, tear apart and reposition a CSS window off to the side, hover over rules, and in another window zoom out and see all the HTML tags it applies to, with a live preview. The state of the art is lame. – Triynko Feb 08 '17 at 15:30
  • @Triynko That sounds more fun than work! Maybe the reason Microsoft hasn't come out with it is to prevent *themselves* from getting distracted. ;-) – jpaugh Feb 21 '17 at 15:25
  • Any updates for VS 2019? Went through all the languages listed for 64OS and still unavailable :/ Running Windows 10 – Nyra Jul 27 '20 at 17:54
28

Go to menuWindowsNew Window:

Enter image description here

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Kishore Sahasranaman
  • 3,243
  • 1
  • 20
  • 45
21

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
masih
  • 530
  • 1
  • 4
  • 9
19

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
  • 2
    (Sri: sorry, 'horizontal' as in the views' rows are aligned ... or one view above the other). AFAIK, vertical (side-by-side) views are not possible. –  Apr 21 '09 at 11:25
  • 8
    Appears not to have read OP, where he mentions he is aware of this very thing. – Jason S Nov 18 '11 at 01:30
11

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
9

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
dumbledad
  • 12,928
  • 20
  • 97
  • 226
  • 3
    Thanks. This worked for me for VS2012/VB.net. Opened Tools - options - (under environment)keyboard - select visual basic 6 from dropdown - select Window.NewWindow from command list - pressed ctrl + n, ctrl + w – CodingSlayer Jan 08 '13 at 15:54
6

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

  1. Open the file.

  2. Click Window -> New Window.

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

  4. Click on Window -> New Vertical Document Group.

Result: enter image description here

Taimoor
  • 311
  • 3
  • 9
4

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

Anton Gogolev
  • 107,051
  • 37
  • 191
  • 278
3

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
mike
  • 1,198
  • 9
  • 27
  • Worked easily for me! Menu **Tools** > **Customize**. Then in **Commands** tab, select **Window** in the first dropdown, then click **Add Command** button and voilà! (Visual Studio 2019) – cyberponk Apr 17 '20 at 00:29
3

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.
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
1

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.

Jason S
  • 1,029
  • 16
  • 21
Gishu
  • 126,803
  • 45
  • 214
  • 298
  • @Odrade - Can you point me to the correct answer that works for all types of files... – Gishu Aug 17 '11 at 02:20
  • @Jason Ok, but it's still incorrect to state that you can't open the same file multiple times to to side-by-side comparison. This is clearly possible, at least for .cs files. – Odrade Nov 17 '11 at 20:12
  • @Odrade You are right. I've edited to try and correct that. Letting you know in case you want to remove comments based on previous versions. – Jason S Nov 17 '11 at 21:11
  • @Odrade Got around to trying [Luke's answer](http://stackoverflow.com/questions/728949/open-two-instances-of-a-file-in-single-visual-studio-session/7396899#7396899) It is far better than opening two instances of VS for VB users and has my upvote. – Jason S Nov 18 '11 at 01:05
  • This seems the only working workaround for html files, where the registry edit just gives a blank second window – Chris F Carroll May 15 '15 at 08:31
1

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
si618
  • 15,970
  • 12
  • 63
  • 81
  • On my VS2K5 and VS2K8 it just shows the original instances in the second tab for me. This is if I double click in Solution Explorer, Drag'n'drop from File Explorer, or via File | Open menu. – Simeon Pilgrim Apr 16 '09 at 01:20
  • @Simeon - That happens if there isn't another file open (2nd part of step 1.) – si618 Apr 23 '09 at 07:40
  • It knows the original file is opened in the other tab group. Maybe this relates again to the files it permits to duplicate. – neoswf Mar 30 '11 at 16:27
0

I came up with a hack that might produce the result intended in the original answer.

If you have the file you want in two windows in a source control, you can right-click on the file and select compare, you can compare the

If you do compare you will have a new window Called diff, showing you the contents of you file.

This is of course not ideal as the diff window will have the diff colors polluting the text. Note: you can compare the file you want to open to and empty file, and then you will have the window in a very ugly green background.

This is not perfect, it is a hack, but it was the only way I found to really have the same file in two windows.

berserck
  • 485
  • 4
  • 15
0

to work on a two section of a one long file simply use shortcut ( Ctrl + \ ) or click on split editor window while you are on selected Tab. the icon is on top-right of the VS Code. enter image description here