How to jump to the beginning of the current function body in Vim?

As title, if I'm in the middle of function body and the function body is very long, how can I jump back to the beginning of the function body .


Solution 1:

[m

Go to [count] previous start of a method

Works for Java or similar structured languages, and for Python as well.

Solution 2:

C language [[

If your C code is in the non-Egyptian style:

[[

[m only works if you have an enclosing {} around the function, e.g. class { method(){} } for Java / C++.

And this is a good bet that works for both Egyptian and non-Egyptian braces:

?^[^ \t#]

Examples:

void egypt() {
#define DONTCARE 1
    int indented code = 1;
}

void tpyge()
{
#define DONTCARE 1
    int indented code = 1
} 

Solution 3:

For functions contained in a pair of curly-braces {}:

Jump to beginning: [{

Jump to end: ]}

Replace the curly-blackets by parens or square-brackets for functions that use those.