How do I jump between method or function definitions in Vim?
Answer
]m / [m
Explanation
Vim's ]m and [m motions navigate between method and function boundaries in curly-brace languages like C, Java, JavaScript, and Go. They are part of Vim's built-in bracket motions and require no plugins.
How it works
]m— jump to the start of the next method (the{opening a function/method body)[m— jump to the start of the previous method]M— jump to the end of the next method (the closing})[M— jump to the end of the previous method
Vim detects method boundaries by looking for { characters that follow a function signature pattern. This is heuristic-based and works best in C, Java, and JavaScript-style files.
Example
Given this JavaScript file:
function alpha() {
doSomething();
}
function beta() {
doSomethingElse();
}
With the cursor anywhere inside alpha, pressing ]m moves to the opening { of beta. Pressing ]M moves to the closing } of beta.
Tips
- Combine with operators:
d]Mdeletes from the cursor to the end of the current method v]Mvisually selects to the method end — useful for selecting an entire function body- A count prefix works:
3]mjumps three methods forward - For Python or indentation-based languages,
[[/]]jump between top-level sections instead