Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Jump to Beginning of Function

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 top or the 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? } 
like image 603
wootscootinboogie Avatar asked Jan 06 '15 18:01

wootscootinboogie


People also ask

How do you get to the start of a function in VS Code?

Go to Enclosing Block (Ctrl + Alt + UpArrow) allows you to quickly navigate up to the beginning of the enclosing code block.

How do you go to the beginning of a line in Visual Studio?

If you don't change the scope then the Home key won't work. Then try using the Home key. It should work.

How do I go back to previous function in Visual Studio?

Go to Definition# You can go back to your previous location with the Go > Back command or Ctrl+Alt+-. You can also see the type definition if you press Ctrl (Cmd on macOS) when you are hovering over the type.


2 Answers

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

This is the shortcut for EditorContextMenus.Navigate.GoToContainingBlock. So you may have to execute this shortcut multiple times if you are a few block layers deep, but it'll get you where you want to go.

like image 108
Anthony Avatar answered Oct 05 '22 10:10

Anthony


Alt+Ctrl+UP,Tab,Tab,Enter
This sequence will move you through Project selctor > Scope selector > Function selector > Current Function.

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

Note:
If you have difficulty in finding a line immediately enclosed by the function(for example, when the function has lots of nested blocks), you can always goto the beginning to collapse the function.

like image 20
Chief A Avatar answered Oct 05 '22 08:10

Chief A