How do I jump between method or function definitions in Vim?
Answer
[m and ]m
Explanation
The [m and ]m motions jump to the start of method/function definitions in languages with brace-delimited blocks. These are designed for navigating code structure quickly without searching for specific function names.
How it works
]m— jump to the start of the next method/function[m— jump to the start of the previous method/function]M— jump to the end of the next method/function[M— jump to the end of the previous method/function- These look for unmatched
{and}at certain indentation levels
Example
func getData() { ← [m jumps here
...
} ← [M jumps here
func process() { ← ]m jumps here
...
} ← ]M jumps here
Tips
- Works best with C-like languages (C, Java, Go, JavaScript)
- For Python, use
]]and[[or Treesitter-based navigation instead - These motions work as operators:
d]mdeletes to the next method start - With Treesitter textobjects,
]mcan be remapped to syntax-aware function jumping for any language