Open two instances of a file in a single Visual St

2019-01-12 13:35发布

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.

13条回答
干净又极端
2楼-- · 2019-01-12 13:49

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.
查看更多
欢心
3楼-- · 2019-01-12 13:53

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

查看更多
闹够了就滚
4楼-- · 2019-01-12 13:55

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

查看更多
地球回转人心会变
5楼-- · 2019-01-12 13:58

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
查看更多
做自己的国王
6楼-- · 2019-01-12 13:59

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.

查看更多
倾城 Initia
7楼-- · 2019-01-12 14:03

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.

查看更多
登录 后发表回答