vs2008 vs2010 添加跳转到函数开头的快捷键

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/W_SX12553/article/details/38846983

情景: 近来在查找接手一个新的项目。需要不断的跳转, 如安装了VAssistX插件像 ALT+O打开文件对应的cpp或h文件,Shift+Alt+F查找所有的引用,还有一些按F12无法跳转过去的定义,按Alt+G 就好了。。。 这里不再一一叙述。。  

近期接触到的一些函数太长,有时在函数的某一部分,要滚动一两屏才能回到函数的开头,用鼠标或pgUp按键实属麻烦啊。。。




解决方案: 查看Tools --> Macros --> Macro Explorer 里面,打开宏编译器(这个和office 系列的宏类似), 在里面你可以写一些宏实现自己的想法,比如文件头注释,函数的注释啊。。    这里我要的跳转到一个函数开头的宏已经有了,  BeginningOfFunction 即是。。


最后,添加快捷键,Tools --> Customize... --> (左下角Keyboard) --》



我这里自己设置 Ctrl+H 为跳转到函数开头处。。。



附 编译器一些有用的宏,自己打开宏编译器加进去即可

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module FunctionNote
    ' --------------------------------------------------
    ' 生成个人  修改者  时间  e.g. "Modified/Note By BenWeng 2014-08-27"
    ' --------------------------------------------------
    Sub ModifiedDescription()
        Dim textSelection As EnvDTE.TextSelection

        textSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
        textSelection.Text = "// Modified/Note By BenWeng " + System.DateTime.Now.Year.ToString + "-" + System.DateTime.Now.Month.ToString + "-" + System.DateTime.Now.Day.ToString + " " + System.DateTime.Now.ToLongTimeString()

    End Sub

    ' --------------------------------------------------
    ' 生成文件说明注释
    ' --------------------------------------------------
    Sub FileDescription()
        Dim gAuthor As String = "YuJian"
        Dim gCompany As String = "Company"

        Dim outTextDoc As TextDocument
        Dim outText As EditPoint

        DTE.ActiveDocument.Selection.GotoLine(1)
        outTextDoc = DTE.ActiveDocument.Object("TextDocument")
        outText = outTextDoc.StartPoint.CreateEditPoint()
        outText.Insert("/*" + vbCrLf)
        outText.Insert(" * Copyright(C) " + Date.Today.Year.ToString() + "," + gCompany + " 保留所有权利。( All rights reserved. )" + vbCrLf)
        outText.Insert(" * " + vbCrLf)
        outText.Insert(" * 文件名称:" + DTE.ActiveDocument.Name + vbCrLf)
        outText.Insert(" * 摘    要:" + vbCrLf)
        outText.Insert(" * 当前版本:1.0" + vbCrLf)
        outText.Insert(" * 作    者:" + gAuthor + vbCrLf)
        outText.Insert(" * 创建日期:" + Date.Today.ToLongDateString() + vbCrLf)
        outText.Insert(" */" + vbCrLf)
        DTE.ActiveDocument.Selection.GotoLine(10)
    End Sub

    ' --------------------------------------------------
    ' 生成函数说明注释
    ' --------------------------------------------------
    Sub FunctionRemark()
        Dim preSpaceCount As Integer = 0   ' 注释前面的空格数, 缩进(单位:字符)
        Dim outTextDoc As TextDocument
        Dim outText As EditPoint
        Dim iCurrentLineNumber As Integer

        iCurrentLineNumber = DTE.ActiveDocument.Selection.CurrentLine '.ToString()
        outTextDoc = DTE.ActiveDocument.Object("TextDocument")
        outText = outTextDoc.StartPoint.CreateEditPoint()
        ' 移动文本输入点到指定行上
        outText.MoveToLineAndOffset(iCurrentLineNumber, 1)
        Dim strSpace As String = ""
        Dim iSpaceIndex As Integer
        For iSpaceIndex = 1 To preSpaceCount
            strSpace = strSpace + " "
        Next
        outText.Insert(strSpace + "//-----------------------------------------------------------" + vbCrLf)
        outText.Insert(strSpace + "// 函数名称:" + vbCrLf)
        outText.Insert(strSpace + "//     " + vbCrLf)
        outText.Insert(strSpace + "// 参数:" + vbCrLf)
        outText.Insert(strSpace + "//    - " + vbCrLf)
        outText.Insert(strSpace + "// 返回:" + vbCrLf)
        outText.Insert(strSpace + "//     " + vbCrLf)
        outText.Insert(strSpace + "// 说明:" + vbCrLf)
        outText.Insert(strSpace + "//     " + vbCrLf)
        outText.Insert(strSpace + "//-----------------------------------------------------------" + vbCrLf)
    End Sub

    ' --------------------------------------------------
    '
    ' 函数注释解析部分
    '
    ' --------------------------------------------------
    Public Structure ITEMDATA
        Public itemType As Integer
        Public itemText As String
    End Structure
    Public lItemList As New System.Collections.Generic.List(Of ITEMDATA)(4)
    Private Function ParseFunctionDescription(ByVal funText As String) As Boolean
        Dim strItem As String
        Dim idata As ITEMDATA
        Dim strSplit As String() = funText.Split("(")

        If strSplit.Length = 1 Then
            Return False
        End If

        '解析函数名称部分
        If strSplit.Length > 2 Then
            strItem = strSplit(strSplit.Length - 2).Trim()
        Else
            strItem = strSplit(0).Trim()
        End If
        Dim strHeadSplit As String() = strItem.Split(" ")
        strItem = strHeadSplit(strHeadSplit.Length - 1).Trim()
        idata.itemType = 1
        idata.itemText = strItem.Trim()
        lItemList.Add(idata)

        '解析参数部分
        strItem = strSplit(strSplit.Length - 1).Trim()
        If strItem.Substring(0, 1) <> ")" Then
            Dim iend As Integer = strItem.IndexOf(")", 0)
            Dim strParams As String = strItem.Substring(0, iend).Trim()
            Dim strParamSplit As String() = strParams.Split(",")
            For Each strItem In strParamSplit
                idata.itemType = 2
                idata.itemText = strItem.Trim()
                lItemList.Add(idata)
            Next strItem
        Else
            idata.itemType = 2
            idata.itemText = "无参数"
            lItemList.Add(idata)
        End If
        '解析返回值类型
        Dim iIndex As Integer
        For iIndex = 0 To strHeadSplit.Length - 2
            idata.itemType = 3
            idata.itemText = strHeadSplit(iIndex).Trim()
            lItemList.Add(idata)
        Next iIndex
        Return True
    End Function

    ' --------------------------------------------------
    '
    ' 根据函数声明生成注释
    '
    ' --------------------------------------------------
    Sub MakeFunctionRemark()
        Dim preSpaceCount As Integer = 0   ' 注释前面的空格数, 缩进(单位:字符)
        Dim outTextDoc As TextDocument
        Dim outText As EditPoint
        Dim iCurrentLineNumber As Integer
        Dim iLineLength As Integer
        Dim strFunText As String
        Dim iItemIndex As Integer
        Dim idata As ITEMDATA

        lItemList.Clear()

        iCurrentLineNumber = DTE.ActiveDocument.Selection.CurrentLine.ToString()
        outTextDoc = DTE.ActiveDocument.Object("TextDocument")
        outText = outTextDoc.StartPoint.CreateEditPoint()
        ' 移动文本输入点到指定行上
        outText.MoveToLineAndOffset(iCurrentLineNumber, 1)
        iLineLength = outText.LineLength
        strFunText = outText.GetText(iLineLength)
        iLineLength = strFunText.Trim().Length
        '但前行没有内容直接返回
        If iLineLength = 0 Then
            Return
        End If

        ' 解析函数名称
        Dim bResult As Boolean = ParseFunctionDescription(strFunText.Trim())
        If bResult = False Then
            lItemList.Clear()
            Return
        End If

        Dim pcount As Integer = 0
        Dim rcount As Integer = 0
        Dim strSpace As String = ""
        Dim iSpaceIndex As Integer
        For iSpaceIndex = 1 To preSpaceCount
            strSpace = strSpace + " "
        Next
        outText.Insert(strSpace + "//-----------------------------------------------------------" + vbCrLf)
        For iItemIndex = 0 To lItemList.Count - 1
            idata = lItemList.Item(iItemIndex)
            Select Case idata.itemType
                Case 1
                    outText.Insert(strSpace + "//     " + vbCrLf)
                    outText.Insert(strSpace + "//  函数名称:" + idata.itemText + vbCrLf)

                    outText.Insert(strSpace + "//     " + vbCrLf)
                Case 2

                    If idata.itemText = "无参数" Then
                        outText.Insert(strSpace + "//  参    数: -无" + vbCrLf)
                        outText.Insert(strSpace + "//     " + vbCrLf)

                    Else
                        If pcount = 0 Then
                            outText.Insert(strSpace + "//  参    数:" + vbCrLf)
                        End If
                        pcount = pcount + 1
                        outText.Insert(strSpace + "//    - " + idata.itemText + vbCrLf)
                        outText.Insert(strSpace + "//     " + vbCrLf)
                    End If

                Case 3
                    If rcount = 0 Then
                        outText.Insert(strSpace + "//  返    回:" + idata.itemText + vbCrLf)
                        outText.Insert(strSpace + "//     " + vbCrLf)
                    End If
                    rcount = rcount + 1
                Case 4
                Case 5
            End Select
        Next
        outText.Insert(strSpace + "//  函数作用:" + vbCrLf)
        outText.Insert(strSpace + "//     " + vbCrLf)

        outText.Insert(strSpace + "//  修改日期:" + Date.Today.ToLongDateString() + "  By YuJian" + vbCrLf)
        outText.Insert(strSpace + "// " + vbCrLf)

        outText.Insert(strSpace + "//-----------------------------------------------------------" + vbCrLf)

        lItemList.Clear()   '清楚所有元素
    End Sub



End Module





====End。。



展开阅读全文

没有更多推荐了,返回首页