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

How do I jump to the start of the next method or function?

Answer

]m

Explanation

The ]m command jumps to the start of the next method in Java-style code. It looks for the next { that appears in the first column or after a method-like pattern.

How it works

  • ]m moves forward to the next start of a method
  • It searches for opening braces { at certain indentation levels
  • Works best with C, Java, and similar brace-delimited languages

Example

void foo() {
    ...
}

void bar() {
    ...
}

With the cursor inside foo, pressing ]m jumps to the opening { of bar.

Tips

  • [m jumps backward to the previous method start
  • ]M jumps to the end of the next method
  • [M jumps to the end of the previous method
  • These motions work best with properly formatted code

Next

How do you yank a single word into a named register?