If I have a function declared as such:
public static void main(String[] args){
blahblahlbah;
}
Is there anyway to move from the "p" in public
to the ending "}" of the function?
It can be assumed that the method body is of considerable length and does contain curly braces if that makes a difference.
Thanks!
Try this key sequence: f{%
Should do it.
There is not a few ways to accomplish the movement.
The most appropriate motion command is
]M
which is short and to the point: It moves the cursor to the end of the next method in a Java-like source code.
There are also three satellite motions that together with ]M
give
possibility to jump to next or previous starts and ends of methods, see :help
]m
and below. Therefore, in addition to ]M
, in this situation one can
issue
]m%
The rest of the answer contains discussion of some tricks that should be used only if the aforementioned motion commands for some reason have failed to solve the problem in your case.
Another simple idea to take advantage of is to jump over the argument list, find the next opening curly brace and move to its closing counterpart,
%l%
or
f{%
or even
/%
Enter%
A similar idea to move the cursor to the very beginning of the method's body and than jump to the next unmatched closing curly brace leads to the following command,
j]}
Note, though, that three of the last four commands work only if the function header is a single line. If that is not the case, they need modifications.
Under some assumptions on the code formatting, it is also possible to achieve the same result using plain-text-oriented movements. If the opening curly brace is the last character on the method header line, one can use
$%
or
g_%
if that brace is the last non-blank character.
In conclusion, stick to the ]M
movement as far as it works for you (it
should, in the vast majority of cases), fall back upon tricks based on
combinations of other text motion commands, otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With