Most posted methods have a downside or two. Usually, when working withing a class definition of some object oriented language, you might not have an empty line after the function body, because many code formatters put the closing braces of last method and class on consecutive lines. Also, you might have annotations on top of the function. To make matters worse, there might be empty lines within your function body. Additionally you'd prefer a method that works with the cursor anywhere within the function, because having to move it to a specific line or worse, character, takes valuable time. Imagine something like
public class Test {
/* ... */
@Test
public void testStuff() {
// given
doSetup();
// when
doSomething();
// then
assertSomething();
}
}
In this scenario, vap
won't do you any good, since it stops at the first empty line within your function. v{o}
is out for the same reason. va{V
is better but doesn't catch the annotation on top of the method. So what I would do in the most general case is va{o{
. va{
selects the whole function body (caveat: if your cursor is within a nested block, for instance an inner if
statement, then you'll only get that block), o
puts the cursor to the beginning of the selection and {
selects the whole paragraph prepending your selection. This means you'll get the function definition, all annotations and doc comments.
va}o-0
. If{
is at the same line with function signature, for examplevoid helloworlds( int num ) {
, then useva}o0
. – Lepidote