Is there a shortcut to move between header and source file in VC++?

This is a feature I have grown accustomed to in Eclipse (Ctrl+Tab). Is there an equivalent in Visual C++?

104736 次浏览

在 Visual Studio 2013和更高版本中,有一个默认的快捷键: Ctrl + KCtrl + O (您需要按住 Ctrl键入 KO,然后释放 Ctrl)

在早期版本中,请参阅:

VisualStudio 宏可以在 CPP 和 H 文件之间切换

或者

在 Visual Assistant 中打开对应的文件

我是视觉辅助的粉丝。它不便宜,但它提供了比在头和源之间切换更多的功能。我也使用它的开放文件在项目和类浏览功能很多。当然宏是免费的..。

There's also a macro listed on the Whole Tomato support forum which has a few more file mappings.

在 VisualStudio2008和2010中,可以右键单击。Cpp 文件,然后选择“转到头文件”... 它将带您朝一个方向前进。对于另一个方向,如果右键单击在标题中声明的内容,并选择“转到定义”,则会转到另一个方向。如果您选择构造函数,您可能必须经历一个解决歧义的对话框,因为函数名称与类名称匹配,但是如果您选择其他内容,您将直接到达您想要的位置。我知道这是一个双击的方法,而不是一个按键,但它确实做你想要的。

Visual assist also does not support Visual studio express editions. So you are stuck with the macro if you are using that IDE>

In Visual Studio 2008 it's Alt + O.

如果您将鼠标放置在头部的函数声明上,然后按 F12,cpp 文件将在 cpp 文件的定义处打开... ... 我大量使用了这个特性!

您可以将此宏添加到您的 VS 配置(通过 Tools-> Macros-> Macro Explorer) ,然后为其分配一个热键(通过 Tools-> Options-> Environment-> Keyboard)。

我只是写了它(一直想试试这个!)但它似乎工作到目前为止,在 VS2008和 VS2010。

因为它是一个宏,所以你可以编辑它来包含任何你想要的规则(例如查看其他文件夹,或者特殊的命名规则,如果你有一个由多个 cpp 文件或类似文件共享的头)。

下面是宏(我确信它可以写得更好; 我不熟悉 VS 对象,只知道宏正在使用。写到一半的时候) :

Sub FileSwitch()
Try
Dim CurrentPath As String = DTE.ActiveDocument.FullName
Dim OtherPath As String


If (IO.Path.HasExtension(CurrentPath)) Then
Dim CurrentExtension As String = IO.Path.GetExtension(CurrentPath)


Select Case CurrentExtension
Case ".h", ".hpp", ".hxx"
OtherPath = IO.Path.ChangeExtension(CurrentPath, ".cpp")
If (Not IO.File.Exists(OtherPath)) Then
OtherPath = IO.Path.ChangeExtension(CurrentPath, ".c")
If (Not IO.File.Exists(OtherPath)) Then
OtherPath = IO.Path.ChangeExtension(CurrentPath, ".cxx")
End If
End If
Case ".cpp", ".c", ".cxx"
OtherPath = IO.Path.ChangeExtension(CurrentPath, ".h")
If (Not IO.File.Exists(OtherPath)) Then
OtherPath = IO.Path.ChangeExtension(CurrentPath, ".hpp")
If (Not IO.File.Exists(OtherPath)) Then
OtherPath = IO.Path.ChangeExtension(CurrentPath, ".hxx")
End If
End If
Case Else
End Select
If (OtherPath <> Nothing) Then
DTE.ItemOperations.OpenFile(OtherPath)
End If
End If


Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub

下面是一个(非常宽:)的截图,展示了宏编辑器和热键/选项对话框应该是什么样子,以帮助那些不熟悉它们的人:

enter image description here

试试 Visual Assist,它运行了这个特性(以及其他一些特性) :

Http://www.wholetomato.com/

代码浏览功能——头/cpp 交换是其中的一部分——非常好。

(I also really rated its intellisense and refactoring features, but not everybody I've spoken to has agreed with me.)

编辑: 刚刚想起来,Nifty Solution Plugin 也可以做到这一点——再加上另一个类似于手工视觉辅助的东西,虽然没有其他功能——而且它们是免费的:

http://code.google.com/p/niftyplugins/

(这家伙的 perforce 插件也很棒,比默认的 VSSCC 垃圾好多了。)

尝试 PhatStudio。它是免费的,并且带有一个简单的安装程序。

  • ALT + S = 在头/源文件之间切换

  • ALT + O = 打开一个文件(支持通过键入即时搜索,如 Windows Vista/7中的开始菜单)。

尝试使用 Switch-这是一个可以让你在源代码和页眉、代码和设计器、 XAML 和代码隐藏等等之间切换的插件:

Http://www.dwmkerr.com/switch/或直接从视觉工作室的产品和扩展

I don't see this answer here, but at least in Visual Studio 2012 (Express included!), you can just assign your own keyboard command to go to the header file (NOTE: Only goes one way -- you can't go back to the source file unfortunately...)

  1. Go to Tools/Options/Environment/Keyboard.
  2. 找到以下命令: EditorContextMenus. CodeWindow.GoToHeaderFile
  3. 分配任何您想要的密钥组合(Alt-S 工作)
  4. 利润

不确定 VS 的哪个版本可以使用,但是它不需要任何外接程序,而且似乎至少在一个方向上可以实现这个功能。

在 Visual Studio 2013中,默认的快捷键是 Ctrl + KCtrl + O

在他们有限的智慧,微软决定删除宏在 MSVS 2012年,所以上面的宏不会工作。

对于 MSVS 2012,我发现:

http://www.dwmkerr.com/switch/

It's highly configurable + if you want to help improving it, you can do so on GitHub.

对于 VisualStudio2013,正如其他人提到的,它是命令名为:

EditorContextMenus.CodeWindow.ToggleHeaderCodeFile

它有默认的键组合: Ctrl + KCtrl + O,但是如果您在

按快捷键:

低于

工具-> 选项-> 环境-> 键盘。

因此,您可以选择一个自定义键组合作为我最喜欢的。 h 到。 cpp 开关是 Ctrl + Tab

在 Visual Studio 2013中,它是 ALT + O