How do I quickly jump between method or function definitions in code?
Answer
]m and [m
Explanation
The ]m and [m motions let you jump forward and backward between the start of method or function definitions. These are especially useful in Java, C, and similar languages where methods are delimited by braces. Combined with their uppercase variants ]M and [M, you can navigate to both the beginning and end of methods without searching.
How it works
]m— jump forward to the next start of a method (next unmatched{)[m— jump backward to the previous start of a method]M— jump forward to the next end of a method (next unmatched})[M— jump backward to the previous end of a method- All four accept a count:
3]mjumps forward 3 methods
These motions look for unmatched braces — a { that opens a block at the method level, not nested braces inside the method body.
Example
Given this code with the cursor at the top:
class Example {
void foo() { <- [m jumps here (backward)
// ...
} <- [M jumps here
void bar() { <- ]m jumps here (forward)
// ...
} <- ]M jumps here
}
Tips
- These work as motions with operators:
d]mdeletes from cursor to the next method start,v]mvisually selects to it - For languages without braces (Python, Ruby), consider treesitter-based navigation in Neovim instead
- Combine with
zzfor centering:]mzzjumps to the next method and centers the screen - Pair with
%once at a brace to jump to its match