visual-studio 如何在 VS2010 中的标题和实现之间切换?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4183674/
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
How to switch between header and implementation in VS2010?
提问by grigoryvp
Is it any keyboard shortcut or free addon in Visual Studio 2010 that allows to switch between header (C/C++ .h file) and implementation (C/C++ .cpp file)?
Visual Studio 2010 中是否有任何键盘快捷键或免费插件允许在标头(C/C++ .h 文件)和实现(C/C++ .cpp 文件)之间切换?
采纳答案by Cody Gray
Visual Studio does not have a built-in keyboard shortcut to switch back and forth. A macro is by far your best bet if you want to automate this with a single keyboard shortcut. For a list of suggested options, see the answers to a previous question.
Visual Studio 没有用于来回切换的内置键盘快捷键。如果您想使用单个键盘快捷键自动执行此操作,宏是迄今为止最好的选择。有关建议选项的列表,请参阅上一个问题的答案。
The add-in Visual Assist Xprovides this featurewith the shortcut Alt+O(however, add-ins are not supported by the Express editions of Visual Studio).
加载项Visual Assist X通过快捷方式+提供此功能(但是,Visual Studio 的 Express 版本不支持加载项)。AltO
If you're trying to avoid using a macro, there is an alternative way to achieve a similar result, although it is a two-click process:
如果您试图避免使用宏,还有一种替代方法可以实现类似的结果,尽管这是一个双击过程:
- To switch from header to implementation:Right-click a.cpp file and choose "Go To Header File" from the context menu.
To switch from implementation to header:Right-click an identifier declared in the header and choose "Go To Definition" from the context menu.
- 从头文件切换到实现:右键单击 a.cpp 文件,然后从上下文菜单中选择“转到头文件”。
从实现切换到标题:右键单击标题中声明的标识符,然后从上下文菜单中选择“转到定义”。
回答by Anton K
MS added this feature in Visual Studio 2013. It's a default keyboard shortcut Ctrl+ K, Ctrl+ O
MS 在 Visual Studio 2013 中添加了此功能。这是默认的键盘快捷键Ctrl+ K, Ctrl+O
To clarify: Keep Ctrlpressed, type K, type O, release Ctrl.
澄清:Ctrl按住,输入 K,输入 O,释放Ctrl。
You can find the command this maps to from the customize-keyboard options as well (tested for VS2015):
您也可以从自定义键盘选项中找到此映射到的命令(针对 VS2015 进行了测试):
回答by Wyck
My workaround to this problem is a bit unorthodox but it might help others, so I'll share.
我解决这个问题的方法有点不正统,但它可能会帮助其他人,所以我会分享。
I use the window list. And I thought it would annoy the heck out of me doing it this way, but I've actually gotten quite used to it. It continues to apply, even in Visual Studio 2012, so I'm offering it as yet another alternative.
我使用窗口列表。我认为这样做会惹恼我,但实际上我已经习惯了。它继续适用,即使在 Visual Studio 2012 中也是如此,因此我将它作为另一种选择提供。
Once both the .cpp and .h files are open, I switch between them like this...
打开 .cpp 和 .h 文件后,我会像这样在它们之间切换...
- To switch from .cpp to .h:
Alt+W, W, Down Arrow, Enter - To switch from .h to .cpp:
Alt+W, W, Up Arrow, Enter
- 从 .cpp 切换到 .h:
Alt+W, W, Down Arrow, Enter - 从 .h 切换到 .cpp:
Alt+W, W, Up Arrow, Enter
You can actually hold down the Altkey while pressing the Wthe second time, effectively making it: Alt+W, Alt+W, Down Arrow, Enter(You don't have to release the Altkey until you type the arrow key)
您实际上可以在第二次Alt按下时按住该键W,从而有效地使其:( 在您键入箭头键之前Alt+W, Alt+W, Down Arrow, Enter不必松开该Alt键)
This works because the .cpp and .h files are typically adjacent alphabetically in the window list. It also works for .c and .h for the same reason. Breaking it down: Alt+Wgoes to the "Window" menu, and the second Wactivates the "Windows..." window list viewer. The active window will be selected in the list box, so pressing the up or down arrow key will move to the document that is before or after alphabetically, which is almost always the corresponding .h/.cpp file.
这是有效的,因为 .cpp 和 .h 文件通常在窗口列表中按字母顺序相邻。出于同样的原因,它也适用于 .c 和 .h。分解: Alt+W转到“窗口”菜单,第二个W激活“Windows...”窗口列表查看器。活动窗口将在列表框中被选中,因此按向上或向下箭头键将移动到按字母顺序排列在前面或后面的文档,该文档几乎总是对应的 .h/.cpp 文件。
As yet another alternative, I should also mention that if you place the .cpp and .h files beside each other in the window tabs, then you can use: Ctrl+Alt+Page Up, and Ctrl+Alt+Page Downto switch between adjacent tabs in the tabbed window list.
作为另一种选择,我还应该提到,如果您将 .cpp 和 .h 文件并排放置在窗口选项卡中,那么您可以使用:Ctrl+Alt+Page Up和Ctrl+Alt+Page Down在选项卡式窗口列表中的相邻选项卡之间切换。
I realize that you have to "prepare" by having both documents open, and this is less than ideal, but I typically have all my documents open anyway, and I use the Alt+W, Wshortcut a lot.
我意识到您必须通过打开两个文档来“准备”,这不太理想,但我通常会打开所有文档,并且我经常使用Alt+W, W快捷方式。
回答by copperoxide
Such shortcut key is added in CodeMaid. CodeMaid is an open source Visual Studio extension
CodeMaid中增加了这样的快捷键。CodeMaid 是一个开源的 Visual Studio 扩展
Ctrl + M then ,
Ctrl + M 然后,
http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496/
http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496/
回答by Eric
In VS2010 - The keyboard shortcut "EditorContextMenu.CodeWindow.GoToHeaderFile" does the same thing as the right click menu. Unfortunately it doesn't work as a toggle to switch back again. (Though, you can use ctrl - to go navigate back if you started in the cpp).
在 VS2010 中 - 键盘快捷键“EditorContextMenu.CodeWindow.GoToHeaderFile”与右键单击菜单执行相同的操作。不幸的是,它不能作为再次切换回来的开关。(不过,如果您在 cpp 中开始,您可以使用 ctrl - 返回导航)。


