VS2010中如何切换头文件和实现?
Visual Studio 2010 中是否有允许在标头(C/C++ .h 文件)和实现(C/C++ .cpp 文件)之间切换的键盘快捷键或免费插件?
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)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
MS 在 Visual Studio 2013 中添加了此功能。它是默认键盘快捷键 Ctrl + K、Ctrl + O
澄清:按住 Ctrl,输入 K,输入 O,松开 Ctrl。
您也可以从自定义键盘选项中找到该命令映射到的命令(针对 VS2015 进行测试):
MS added this feature in Visual Studio 2013. It's a default keyboard shortcut Ctrl + K, Ctrl + O
To clarify: Keep Ctrl pressed, type K, type O, release Ctrl.
You can find the command this maps to from the customize-keyboard options as well (tested for VS2015):
Visual Studio 没有内置的键盘快捷键来来回切换。如果您想使用单个键盘快捷键自动执行此操作,宏是迄今为止您的最佳选择。有关建议选项的列表,请参阅
插件 Visual Assist X 提供了此 功能,使用快捷键 Alt+O(但是,不支持加载项由 Visual Studio Express 版本提供)。
如果您试图避免使用宏,还有另一种方法可以实现类似的结果,尽管这是一个两次单击的过程:
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.
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.
The add-in Visual Assist X provides this feature with the shortcut Alt+O (however, add-ins are not supported by the Express editions of Visual Studio).
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.
我解决这个问题的方法有点非正统,但可能对其他人有帮助,所以我会分享。
我使用窗口列表。我以为这样做会让我很恼火,但实际上我已经习惯了。即使在 Visual Studio 2012 中,它仍然适用,因此我将其作为另一种替代方案提供。
一旦 .cpp 和 .h 文件都打开,我会像这样在它们之间切换...
Alt+W、W、向下箭头、Enter
Alt+W、W、向上箭头、Enter
实际上,您可以在按住
Alt
键的同时按W
第二次,有效地做到这一点:Alt+W、Alt+W、向下箭头、Enter
(在键入箭头键之前,您不必释放Alt
键)这是可行的,因为 .cpp 和 .h 文件通常在窗口列表中按字母顺序相邻。出于同样的原因,它也适用于 .c 和 .h。分解:
Alt+W
转到“窗口”菜单,第二个W
激活“Windows...”窗口列表查看器。将在列表框中选择活动窗口,因此按向上或向下箭头键将移动到按字母顺序排列之前或之后的文档,这几乎总是相应的 .h/.cpp 文件。作为另一种选择,我还应该提到,如果您将 .cpp 和 .h 文件放在窗口选项卡中,则可以使用:
Ctrl+Alt+Page Up
和Ctrl+Alt+Page Down
在选项卡式窗口列表中的相邻选项卡之间切换。我意识到您必须通过打开两个文档来“准备”,这不太理想,但我通常会打开所有文档,并且我使用
Alt+W, W
快捷键很多。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.
Once both the .cpp and .h files are open, I switch between them like this...
Alt+W, W, Down Arrow, Enter
Alt+W, W, Up Arrow, Enter
You can actually hold down the
Alt
key while pressing theW
the second time, effectively making it:Alt+W, Alt+W, Down Arrow, Enter
(You don't have to release theAlt
key until you type the arrow key)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+W
goes to the "Window" menu, and the secondW
activates 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.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
, andCtrl+Alt+Page Down
to switch between adjacent tabs in the tabbed window list.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, W
shortcut a lot.CodeMaid中添加了这样的快捷键。 CodeMaid 是一个开源 Visual Studio 扩展
Ctrl + M 然后 ,
http:// /visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496/
Such shortcut key is added in CodeMaid. CodeMaid is an open source Visual Studio extension
Ctrl + M then ,
http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496/
在 VS2010 中 - 键盘快捷键“EditorContextMenu.CodeWindow.GoToHeaderFile”与右键单击菜单具有相同的功能。不幸的是,它不能作为再次切换回来的开关。 (不过,如果您在 cpp 中启动,则可以使用 ctrl - 导航回来)。
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).