Visual Studio Jump to Beginning of Function

前端 未结 7 887
情书的邮戳
情书的邮戳 2021-02-05 00:48

I know that Ctrl+} will take you to the corresponding brace in Visual Studio, but say I\'m in the middle of a gigantic function and I don\'t know where the

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-05 01:42

    You can do it with Macros for Visual Studio extension.

    Here's the code for macros:

    // BeginningOfFunction moves the caret to the beginning of the containing definition.
    
    var textSelection = dte.ActiveDocument.Selection;
    
    // Define Visual Studio constants
    var vsCMElementFunction = 2;
    
    var codeElement = textSelection.ActivePoint.CodeElement(vsCMElementFunction);
    
    
    if (codeElement != null)
    {
        textSelection.MoveToPoint(codeElement.GetStartPoint());
        dte.ActiveDocument.Activate();
    }
    

    It is one of the sample macros of the extension. Edited it a little, because for some reason sample didn't work for me. You can get to the end of the function by changing codeElement.GetStartPoint() to codeElement.GetEndPoint().

提交回复
热议问题