Reputation: 1176
I'm a vim user and recently I started learning writing apps for Android.
I use Android Studio 2.3.2 with Vim emulator.
As it comes to Vim- I usually use it for C++ programming and one of the features I use on a daily basis is ]] to move to the next function and [[ to get to the previous function.
When I use that in Android Studio it just moves me to the beginning/end of the file.
My guess is that it is related with opening function scope in the same line instead of in the new line.
Question:
Is that possible to jump to next/previous function using Android Studio Vim emulator just as I used to do in C++ code (even though I use Java coding style, a.k.a. "egyptian brackets")?
Upvotes: 0
Views: 553
Reputation: 3439
From the docs :help ]]
*]]*
]] [count] sections forward or to the next '{' in the
first column. When used after an operator, then also
stops below a '}' in the first column. |exclusive|
Note that |exclusive-linewise| often applies.
Which means it just goes to the next statement that has '{' as the first character of the line, which happens to be the case C and C++ functions (at least in some styleguides), as methods and functions start with a {
, without any type of nesting.
However, when writing Java, methods are nested inside of classes, which means they usually have a level of indentation.
According to this answer, Vim has the builtin [m
and ]m
mappings, to navigate methods.
*]m*
]m Go to [count] next start of a method (for Java or
similar structured language). When not before the
start of a method, jump to the start or end of the
class. When no '{' is found after the cursor, this is
an error. |exclusive| motion.
So, if you wish to use [[
and ]]
for navigating methods, you could remap these in your ~/.ideavimrc
.
nnoremap [[ [m
nnoremap ]] ]m
Upvotes: 2