Visual Studio Go to Top

I know that Ctrl + } will lead you to the appropriate bracket in Visual Studio, but they say that I'm in the middle of a giant function, and I don’t know where the top or bottom is, is there a shortcut to get directly to the function declaration?

void function() { //so many lines of code //can't see the top or the bottom curly brace //can i get to the top of the function with a shortcut? } 
+20
source share
6 answers

I usually double-click the white line to the left of the code. It closes the function, but also displays you on the function declaration.

+8
source

Alt+Ctrl+UP , Tab , Tab , Enter
This sequence will take you through Project Selector> Scope Selection> Function Selection> Current Function.

Ctrl+M , Ctrl+M
This sequence will switch between collapse / expand the current block.
Place the cursor on any line that is immediately enclosed in a function. Collapse. Place the cursor at the end of the collapsed function, i.e. after {... } . Expand the function to get its last bracket.

Remarks:
If you are having difficulty finding a line directly covered by a function (for example, when a function has many nested blocks), you can always go to the beginning to collapse the function.

+6
source

I have a fresh installation of VS2017. As of 15.9.1, the default value for me is Alt + Shift + [ .

This is a shortcut for EditorContextMenus.Navigate.GoToContainingBlock . Thus, you may need to run this shortcut several times if you are in several layers of the block, but it will lead you to where you want.

+5
source

You can do this with Macros to extend Visual Studio .

Here is the code for the 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(); } 

This is one example of extension macros. Changed it a bit, because for some reason the sample did not work for me. You can skip to the end of the function by changing codeElement.GetStartPoint() to codeElement.GetEndPoint() .

+3
source

Update

With the latest Visual Studio updates, the default keyboard shortcut for EditorContextMenus.Navigate.GoToConistingBlock is now Shift + Alt + [


Old answer:

Visual Studio 2017 version 15.8.0 comes with a new keyboard shortcut Ctrl + Alt + UpArrow - Go to the included block.

Go to the attachment block (Ctrl + Alt + UpArrow) allows you to quickly go to the beginning of the code block.

A source

This command also allows you to jump to the function declaration if you are inside the function. enter image description here

If the shortcut does not work for you

+2
source

I found one trick in visual studio:

Place the cursor on a blank to get the context (function name), copy the function name, then click the drop-down arrow in which all functions will be listed, paste the function name, enter. Then you are at the beginning of this feature!

0
source

Source: https://habr.com/ru/post/980611/


All Articles