visual-studio 更改 Ctrl + Tab 行为以在 Visual Studio 中的文档之间移动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21027/
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
Changing Ctrl + Tab behavior for moving between documents in Visual Studio
提问by Jeff Cuscutis
Is it possible to change how Ctrl+ Taband Shift+ Ctrl+ Tabwork in Visual Studio? I have disabled the popup navigator window, because I only want to switch between items in the tab control. My problem is the inconsistency of what switching to the next and previous document do.
是否可以更改Ctrl+Tab和Shift+ Ctrl+Tab在 Visual Studio 中的工作方式?我已禁用弹出导航器窗口,因为我只想在选项卡控件中的项目之间切换。我的问题是切换到下一个和上一个文档所做的不一致。
Every other program that uses a tab control for open document I have seen uses Ctrl+ Tabto move from left to right and Shift+ Ctrl+ Tabto go right to left. Visual Studio breaks this with its jump to the last tab selected. You can never know what document you will end up on, and it is never the same way twice.
使用开放文档选项卡控制所有其他节目,我已经看到了使用Ctrl+Tab从左向右移动和Shift+ Ctrl+Tab去从右到左。Visual Studio 通过跳转到最后一个选定的选项卡打破了这一点。你永远不知道你最终会得到什么文件,而且它永远不会以同样的方式两次。
It is very counterintuitive. Is this a subtle way to encourage everyone to only ever have two document open at once?
这是非常违反直觉的。这是鼓励每个人一次只打开两个文档的巧妙方法吗?
Let's say I have a few files open. I am working in one, and I need to see what is in the next tab to the right. In every other single application on the face of the Earth, Ctrl+ Tabwill get me there. But in Visual Studio, I have no idea which of the other tabs it will take me to. If I only ever have two documents open, this works great. As soon as you go to three or more, all bets are off as to what tab Visual Studio has decided to send you to.
假设我打开了几个文件。我正在其中一个工作,我需要查看右侧下一个选项卡中的内容。在地球表面的所有其他应用程序中,Ctrl+Tab都会让我到达那里。但是在 Visual Studio 中,我不知道它会带我去哪个其他选项卡。如果我只打开两个文档,这很管用。一旦你进入三个或更多,所有的赌注都关乎 Visual Studio 决定将你发送到哪个选项卡。
The problem with this is that I shouldn't have to think about the tool, it should fade into the background, and I should be thinking about the task. The current tab behavior keeps pulling me out of the task and makes me have to pay attention to the tool.
这样做的问题是我不应该考虑工具,它应该淡入背景,我应该考虑任务。当前的选项卡行为不断将我从任务中拉出来,让我不得不关注该工具。
采纳答案by thepaulpage
In Visual Studio 2015 (as well as previous versions of VS, but you must install Productivity Power Toolsif you're using VS2013 or below), there are two new commands in Visual Studio:
在 Visual Studio 2015(以及以前版本的 VS,但如果您使用的是 VS2013 或更低版本,则必须安装Productivity Power Tools),Visual Studio 中有两个新命令:
Window.NextTaband Window.PreviousTab
Window.NextTab和 Window.PreviousTab
Just go remap them from Ctrl+Alt+PageUp/Ctrl+Alt+PageDownto Ctrl+Tab/Ctrl+Shift+Tabin:
只需将它们从Ctrl+ Alt+ PageUp/ Ctrl+ Alt+重新映射PageDown到Ctrl+ Tab/ Ctrl+ Shift+ Tab:
Menu Tools-> Options-> Environment-> Keyboard
菜单工具->选项->环境->键盘
Note: In earlier versions such as Visual Studio 2010, Window.NextTab and Window.PreviousTab were named Window.NextDocumentWellTaband Window.PreviousDocumentWellTab.
注意:在 Visual Studio 2010 等早期版本中,Window.NextTab 和 Window.PreviousTab 被命名为Window.NextDocumentWellTab和 Window.PreviousDocumentWellTab。
回答by Zoey
Visual Studio 2010 has, built in, a way to solve this.
Visual Studio 2010 内置了解决此问题的方法。
By default, Ctrl+Taband Ctrl+Shift+Tabare assigned to Window.[Previous/Next]..Document, but you can, through
默认情况下,Ctrl+Tab和Ctrl+ Shift+Tab被分配到Window.[Previous/Next]..Document,但是你可以通过
Tools -> Options -> Environment -> Keyboard,
remove those key assignments and reassign them to Window.[Next/Previous]Tabto add the desired behavior.
删除这些键分配并重新分配它们Window.[Next/Previous]Tab以添加所需的行为。
回答by nawfal
it can be changed, at least in VS 2012 (I think it should work for 2010 too).
它可以改变,至少在 VS 2012 中(我认为它也应该适用于 2010)。
1) TOOLS > Options > Environment > Keyboard
1) TOOLS > Options > Environment > Keyboard
(Yes TOOLS, its VS2012 !) Now three shortcuts to check.
(是的工具,它的 VS2012 !)现在要检查三个快捷方式。
2) Window.NextDocumentWindow- you can reach there quickly by typing on the search pane on top. Now this is your enemy. Remove it if you dont like it. Change it to something else (and dont forget the Assignbutton) if want to have your own, but do remember that shortcut whatever it is in the end. It will come handy later.
2) Window.NextDocumentWindow- 您可以通过在顶部的搜索窗格中键入内容来快速到达那里。现在这是你的敌人。如果您不喜欢它,请删除它。如果想拥有自己的,请将其更改为其他内容(不要忘记“分配”按钮),但请记住该快捷方式到底是什么。稍后会派上用场。
(I mean this is the shortcut that remembers your last tab)
(我的意思是这是记住你最后一个标签的快捷方式)


3) Now look for Window.NextDocumentWindowNav- this is the same as above but shows a preview of opened tabs (you can navigate to other windows too quickly with this pop-up). I never found this helpful though. Do all that mentioned in step 2 (don't forget to remember).
3) 现在查找Window.NextDocumentWindowNav- 这与上面相同,但显示打开的选项卡的预览(您可以使用此弹出窗口快速导航到其他窗口)。我从来没有发现这有帮助。执行第 2 步中提到的所有操作(不要忘记记住)。
4) Window.NextTab- your magic potion. This would let you cycle through tabs in the forward order. May be you want CTRL+TAB? Again step 2 and remember.
4) Window.NextTab- 你的魔法药水。这将使您可以按前向顺序循环浏览选项卡。可能你想要CTRL+TAB吗?再次第 2 步并记住。
5) Now place cursor in the Press shortcut keys:textbox (doesn't matter what is selected currently, you're not going to Assignthis time), and type first of the three (or two or one) shortcuts.
5) 现在将光标置于按下快捷键:文本框(当前选择什么无关紧要,这次您不会分配),然后键入三个(或两个或一个)快捷键中的第一个。


You'll see Shortcut currently used by:listed. Ensure that you have no duplicate entry for the shortcut. In the pic, there are no duplicate entries. In case you have (a rarity), say X, then go to X, and remove the shortcut. Repeat this step for other shortcuts as well.
您将看到当前使用的快捷方式:列出。确保快捷方式没有重复的条目。在图片中,没有重复的条目。如果您有(罕见),请说 X,然后转到 X,并删除快捷方式。对其他快捷方式也重复此步骤。
6) Now repeat 1-5 for Previousshortcuts as well (preferably adding Shift).
6)现在也为Previous快捷方式重复1-5 (最好添加Shift)。
7) Bonus: Select VS2005 mapping scheme (at the top of the same box), so now you get F2for Renamemembers and not CTRL+R+R, and F7for View Codeand not CTRL+ALT+0.
7)奖励:选择VS2005映射方案(在同一个盒子的顶部),所以现在你得到F2了重新命名的成员,而不是CTRL+ R+ R,以及F7用于查看代码,而不是CTRL+ ALT+ 0。
I'm of the opinion VS has got it right by default. I find it extremely useful that VS remembers what I used last, and makes switching easier, much like what the OS itself does (on ALT+TAB). My browser does the same too by default (Opera), though I know Firefox behaves differently.
我认为 VS 默认情况下是正确的。我发现 VS 记住我上次使用的内容非常有用,并使切换更容易,就像操作系统本身所做的一样(在ALT+ 上TAB)。我的浏览器在默认情况下也做同样的事情 (Opera),但我知道 Firefox 的行为不同。
回答by Colonel Panic
In Visual Studio 2012 or later (2013, 2015, 2017...):
在 Visual Studio 2012 或更高版本(2013、2015、2017...)中:
- Browse the menu Tools / Options / Environment / Keyboard.
- Search for the command 'Window.NextTab', set the shortcut to Ctrl+Tab
- Search for the command 'Window.PreviousTab', set the shortcut to Ctrl+Shift+Tab
- 浏览菜单工具/选项/环境/键盘。
- 搜索命令'Window.NextTab',将快捷方式设置为Ctrl+Tab
- 搜索命令“Window.PreviousTab”,设置快捷键Ctrl+ Shift+Tab


回答by user178908
Navigate to the blog post Visual Studio Tab Un-stupidifier Macroand make use of the macro. After you apply the macro to your installation of Visual Studio you can bind your favorite keyboard shortcuts to them. Also notice the registry fix in the comments for not displaying the macro balloon since they might get annoying after a while.
导航到博客文章Visual Studio Tab Un-stupidifier Macro并使用该宏。将宏应用到 Visual Studio 的安装后,您可以将您喜欢的键盘快捷键绑定到它们。还要注意注释中的注册表修复不显示宏气球,因为它们可能会在一段时间后变得烦人。
回答by user410261
After a couple of hours of searching I found a solution how to switch between open documents using CTRL+TABwhich move from left to right and SHIFT+ CTRL+ TABto go right to left.
一对夫妇的搜索小时后,我找到了解决如何使用开放文档之间进行切换CTRL+TAB从左侧移动到右, SHIFT+ CTRL+TAB向右向左走。
In short you need to copy and paste this macro:
简而言之,您需要复制并粘贴此宏:
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module TabCtrl
Public Sub TabForward()
Dim i As Integer
Dim activateNext As Boolean = False
For i = 1 To DTE.Windows.Count
If DTE.Windows().Item(i).Kind = "Document" Then
If activateNext Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
If DTE.Windows().Item(i) Is DTE.ActiveWindow Then
activateNext = True
End If
End If
Next
' Was the last window... go back to the first
If activateNext Then
For i = 1 To DTE.Windows.Count
If DTE.Windows().Item(i).Kind = "Document" Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
Next
End If
done:
End Sub
Public Sub TabBackward()
Dim i As Integer
Dim activateNext As Boolean = False
For i = DTE.Windows.Count To 1 Step -1
If DTE.Windows().Item(i).Kind = "Document" Then
If activateNext Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
If DTE.Windows().Item(i) Is DTE.ActiveWindow Then
activateNext = True
End If
End If
Next
' Was the first window... go back to the last
If activateNext Then
For i = DTE.Windows.Count To 1 Step -1
If DTE.Windows().Item(i).Kind = "Document" Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
Next
End If
done:
End Sub
End Module
The macro comes from: www.mrspeaker.net/2006/10/12/tab-un-stupidifier/
宏来自:www.mrspeaker.net/2006/10/12/tab-un-stupidifier/
If you never add a macro to Visual Studio there is a very useful link how to do it.
如果您从不向 Visual Studio 添加宏,则有一个非常有用的链接如何操作。
回答by user410261
The philosophy of the Visual Studio tab order is very counterintuitive since the order of the displayed tabs differs from the tab-switching logic, rendering the ordering of the tabs completely useless.
Visual Studio 选项卡顺序的原理非常违反直觉,因为显示选项卡的顺序与选项卡切换逻辑不同,从而使选项卡的顺序完全无用。
So until a better solution arises, change the window layout (in Environment->General) from tabbed-documents to multiple-documents; it will not change the behaviour, but it reduces the confusion caused by the tabs.
因此,在出现更好的解决方案之前,将窗口布局(在 Environment->General 中)从选项卡式文档更改为多文档;它不会改变行为,但会减少由选项卡引起的混乱。
That way you will also find the DocumentWindowNav more useful!
这样您也会发现 DocumentWindowNav 更有用!
回答by FlashJordan
Ctl+ Alt+ PgUpor PgDnshortcuts worked to toggle next/prev tab out of the box for me...
Ctl+ Alt+PgUp或PgDn快捷方式可以为我切换开箱即用的下一个/上一个选项卡......
回答by buti-oxa
I guess you want what VSS calls Next(Previous)DocumentWindow. By default, it's on Ctrl(-Shift)-F6on my VSS 8. On Ctrl(-Shift)-Tabthey have Next(Previous)DocumentWindowNav. You can change key assignments via Tools/Options/Keyboard.
我猜你想要什么 VSS 调用 Next(Previous)DocumentWindow。默认情况下,它Ctrl(-Shift)-F6在我的 VSS 8上打开。在Ctrl(-Shift)-Tab他们有Next(Previous)DocumentWindowNav. 您可以通过工具/选项/键盘更改键分配。
回答by Kei
I'm 100% in agreement with Jeff.
我 100% 同意杰夫。
I had worked on Borland C++ Builder for several years and one of the features I miss most is the 'correct' document tabbing order with Ctrl-Tab. As Jeff said, "The current tab behavior keeps pulling me out of the task and makes me have to pay attention to the tool" is exactly how I feels about this, and I'm very much surprised by the fact that there aren't many people complaining about this.
我在 Borland C++ Builder 上工作了好几年,我最怀念的功能之一是使用Ctrl-的“正确”文档选项卡顺序Tab。正如杰夫所说,“当前的选项卡行为不断将我从任务中拉出来,让我不得不关注该工具”正是我对此的感受,而且我对没有的事实感到非常惊讶很多人抱怨这个。
I think Ctrl-F6- NextDocumentWindowNav - navigates documents based on the document's last-activated time. This behavior is a lot like how MDI applications used to behave in old days.
我认为Ctrl- F6- NextDocumentWindowNav - 根据文档的上次激活时间导航文档。这种行为很像过去 MDI 应用程序的行为方式。
With this taken this into account, I usually use Ctrl+F6to switch between 2 documents (which is pretty handy in switching between .cpp and .h files when working on c++ project) even when there are more than 2 currently opened documents. For example, if you have 10 documents open (Tab1, Tab2, Tab3, ...., Tab10), I click on Tab1 and then Tab2. When I do Ctrl+F6and release keys, I'll jump to Tab1. Pressing Ctrl+F6again will take me back to Tab2.
考虑到这一点,我通常使用Ctrl+F6在 2 个文档之间切换(在处理 C++ 项目时在 .cpp 和 .h 文件之间切换非常方便),即使当前打开的文档超过 2 个。例如,如果您打开了 10 个文档(Tab1、Tab2、Tab3、....、Tab10),我单击 Tab1,然后单击 Tab2。当我执行Ctrl+F6和释放键时,我将跳转到 Tab1。再次按Ctrl+F6会将我带回 Tab2。

