【问题标题】:What are the VS2010 Navigate to Next/Prev function declaration hotkeys?VS2010 Navigate to Next/Prev 函数声明热键是什么?
【发布时间】:2012-03-30 01:59:15
【问题描述】:

在 Access VB6 代码编辑器中,Ctrl-Up 和 Ctrl-Down 将跳转到下一个/上一个函数声明。

这是一个非常方便的导航工具,我在 VS2010 中似乎找不到。

我在 google 和 stackoverflow 上进行了一些搜索,但似乎找不到任何对它的引用。

有谁知道这些热键在VS2010中是否存在?

如果他们不这样做,他们怎么可能不存在于像 VS2010 这样的上下文感知 IDE 中?

【问题讨论】:

    标签: visual-studio-2010 visual-c++


    【解决方案1】:

    存在热键:http://www.dofactory.com/ShortCutKeys/ShortCutKeys.aspx

    然后转到单独的声明: shift+ctrl+1/shift+ctrl+2

    【讨论】:

    • 这些似乎对我不起作用。知道在 VS2010 热键编辑器中调用的实际命令是什么吗?同样从该页面上的描述来看,它看起来更像是基于光标下的变量/函数进行导航。
    • 这取决于您使用的语言。对于每种语言,微软都提供了一个对应于单独热键集合的 pdf 文件。
    • 啊,干杯。他们似乎没有我正在寻找的热键命令,但这些 pdf 文件仍然非常有用。
    【解决方案2】:

    我认为它们在 VS2010 中不存在,我们在 VS6 和 2010 中都工作,没有这些命令真令人气愤。

    【讨论】:

      【解决方案3】:

      这些天我是自动化的强迫症,已经制作了很多宏来帮助我导航。以下是一些 VB 宏代码,它们将在 C 中执行您想要的操作(也可能是 C++)。您可以在 Visual Studio 中创建一个宏并将这些行添加到其中。检测函数声明的正则表达式可能并不完美,但我已经使用它们一周了,它们对我来说效果很好。您可以将这 2 个宏映射到您想要的键绑定,如果您愿意,可以使用 Ctrl+Up 或 Ctrl+Down。如果有人改进正则表达式,我很乐意看到更新的版本。

      Imports System
      Imports EnvDTE
      Imports EnvDTE80
      Imports EnvDTE90
      Imports EnvDTE90a
      Imports EnvDTE100
      Imports System.Diagnostics
      Imports System.Text.RegularExpressions
      
      Public Module NavigationMacros
          Private Function IsFunctionDeclaration(ByRef LineText As String) As Boolean
              If Regex.IsMatch(LineText, "^[^\s\d\W\(\)]+[^\(\)]+\s+[^\s\d\W\(\)]+\s*\([^\(\)]*\)\s*$") Then
                  IsFunctionDeclaration = True
              Else
                  IsFunctionDeclaration = False
              End If
          End Function
      
          Private Function GetLineText(ByRef EditPoint As EnvDTE.EditPoint) As String
              EditPoint.StartOfLine()
              GetLineText = EditPoint.GetText(EditPoint.LineLength)
          End Function
      
          Sub GoToPreviousFunctionDeclaration()
              Dim Selection As EnvDTE.TextSelection
              Dim EditPoint As EnvDTE.EditPoint
              Dim LineText As String
      
              Selection = DTE.ActiveDocument.Selection
              EditPoint = Selection.TopPoint.CreateEditPoint
      
              EditPoint.LineUp()
      
              While IsFunctionDeclaration(GetLineText(EditPoint)) = False And Not EditPoint.AtStartOfDocument
                  EditPoint.LineUp()
              End While
      
              If Not EditPoint.AtEndOfDocument Then
                  Selection.MoveToLineAndOffset(EditPoint.Line, 1)
              End If
          End Sub
      
          Sub GoToNextFunctionDeclaration()
              Dim Selection As EnvDTE.TextSelection
              Dim EditPoint As EnvDTE.EditPoint
              Dim LineText As String
      
              Selection = DTE.ActiveDocument.Selection
              EditPoint = Selection.TopPoint.CreateEditPoint
      
              EditPoint.LineDown()
      
              While IsFunctionDeclaration(GetLineText(EditPoint)) = False And Not EditPoint.AtEndOfDocument
                  EditPoint.LineDown()
              End While
      
              If Not EditPoint.AtEndOfDocument Then
                  Selection.MoveToLineAndOffset(EditPoint.Line, 1)
              End If
          End Sub
      End Module
      

      【讨论】:

        猜你喜欢
        • 2015-07-30
        • 2020-08-10
        • 1970-01-01
        • 2023-04-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多