vimtricks.wiki Concise Vim tricks, one at a time.

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]m deletes to the next method start
  • With Treesitter textobjects, ]m can be remapped to syntax-aware function jumping for any language

Next

How do I return to normal mode from absolutely any mode in Vim?