visual-studio 在单个 Visual Studio 会话中打开文件的两个实例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/728949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:21:01  来源:igfitidea点击:

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

visual-studioeditor

提问by Paragon

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:

我有一个文件,xyz.cpp。我想在 Visual Studio 中打开这个文件的两个实例(顺便说一句,我使用的是 Visual Studio 2005)。我为什么要这样做?我想并排比较同一文件的两个部分。我知道解决方法,例如:

  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.

  1. 制作文件的副本。但问题是它不优雅,我不想每次遇到这种情况都复制。

  2. 我可以把窗户一分为二。拆分它的问题是我只能水平拆分它。水平分割的结果是我屏幕的右半部分是空白区域。

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.

如果我能够垂直拆分它或打开同一个文件的两个实例,它会增加我可以比较的代码行数。

回答by PaulB

Here's how to do it...

这是如何做到的...

  1. Select the tab you want two copies of
  2. Select menu WindowNew Windowfrom the menu.
  3. Right click the new tab and select New Vertical Tab Group
  1. 选择您想要两个副本的选项卡
  2. 从菜单中选择菜单窗口新窗口
  3. 右键单击新选项卡并选择新建垂直选项卡组

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

如果New Window未在 *Window 菜单中列出,请注意该命令确实存在,即使在 Visual Studio 2017 中也是如此。使用菜单ToolsCustomizeCommands将其添加到Window菜单中。此时决定将New Window命令放在哪里并选择Add Command

UPDATEDon "30 July 2018"

更新于“2018 年 7 月 30 日”

In Visual Studio Code version 1.25.1 and later

在 Visual Studio Code 1.25.1 及更高版本中

Way 1

方式一

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

您可以简单地左键单击侧面板(资源管理器)中的文件,然后按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.

只需在 Visual Studio Code 侧面板(资源管理器)中右键单击您的文件,然后选择open to side的第一个选项。

回答by Luke Hoffmann

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

对于 Visual Basic、HTML 和 JScript 以及 RDL 表达式,PaulB 的回答中Window > New Window提到的选项被禁用。但是,可以在注册表中更改一个选项以启用菜单项。

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

所有其他语言不限于单个代码窗口,因此您无需编辑注册表即可使用PaulB 的答案

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

在 Windows 注册表中启用新窗口。[ 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 Onlyand do one of the following:

    • Set it to 0
    • Rename the value
    • Delete the value (use caution!)
  1. 转到以下注册表项。此示例适用于 Basic (Visual Basic),但关键也适用于 HTML、JScript 和 RDL 表达式。

    • 64 位操作系统: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Languages\Language Services\Basic
    • 32 位操作系统: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Languages\Language Services\Basic
  2. 找到该值Single Code Window Only并执行以下操作之一:

    • 将其设置为 0
    • 重命名值
    • 删除值(小心使用!)

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.

恢复注册表值
将此复制粘贴到记事本,另存为 .reg 文件并将该文件导入您的注册表以恢复初始设置。

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

回答by masih

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

您可以使用WindowsNew Window选项复制当前窗口。查看更多:为什么我喜欢 Visual Studio 2010?取消停靠窗口

回答by masih

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

完成后,抓住拆分器并将其一直向上拖动(或菜单WindowRemove Split)。

回答by Kishore Sahasranaman

Go to menuWindowsNew Window:

转到菜单Windows新窗口

Enter image description here

在此处输入图片说明

回答by dumbledad

Luke's answerdidn'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.

卢克的回答对我不起作用。“新窗口”命令已经在自定义设置中列出,但没有显示在 .js 选项卡上下文菜单中,尽管删除了注册表设置。

So I used:

所以我使用了:

Tools

工具

Customize...

定制...

Keyboard...

键盘...

Scroll down to select Window.NewWindow

向下滚动以选择 Window.NewWindow

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

我按下并分配了快捷键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.

好吧,“有效”太强了。我的键盘快捷键确实在同一个 JavaScript 文件上打开了另一个选项卡,但没有帮助它不呈现内容;它只是一个空的白色窗口!你可能有更好的运气。

回答by Gustavo Rossi Muller

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

随着你打开文件,转到命令窗口(菜单视图其他窗口命令窗口,或者只是Ctrl+ Alt+ A

Type:

类型:

Window.NewWindow

And then

接着

Window.NewVerticalTabGroup

worked for me (Visual Studio 2017).

对我来说有效(Visual Studio 2017)。

Or using menus:

或使用菜单:

Menu WindowNew Window

菜单窗口新窗口

Menu WindowNew vertical tap group

菜单窗口新的垂直点击组

回答by Anton Gogolev

Windowmenu, New Horizontal/Vertical Tab Groupthere will do, I think.

窗口菜单,新的水平/垂直选项卡组就可以了,我想。

回答by mike

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!

在使用 Visual Studio 2013 和 VB.NET 时,我发现您可以非常轻松地自定义菜单并添加“新窗口”命令 - 无需弄乱注册表!

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

天知道为什么微软选择不包括某些语言的命令......?

回答by mike

For newer versions (such as Visual Studio 2017)

对于较新版本(例如 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.
  • 选择要复制的窗口。
  • 转到窗口选项卡,然后单击列表顶部的拆分。
  • 完成后,再次单击它以将其关闭。