Jump to matching bracket

Effortlessly jump back and forth between opposing brackets with %

If you’re programming in Vim, you probably make judicious use of various brackets: parens, square brackets (braces), curly bracket (curly braces), among others. If you’re writing in lisp, then you’re day-to-day existing is a never ending flood of parentheses. Vim has a simple trick built in to make jumping back and forth between opposing sides of brackets easy: Just press the % key.

Here’s a short screencast showing some Clojure code open, with the cursor easily bounding back and forth between the open and close () and [], just by pressing % when on top of either end. This tricks makes finding the matching parenthesis easy.

We’ve heard from a number of you who develop in Ruby and there’s good news: The matchit plugin, which ships with Vim 6.0 and above, extends the % capability to do/end blocks as well. Pressing % on the do will bounce you do the end and vice-versa.

Another common trick often paired with the % command is to remap it to automatically visually select the contents between the matching brackets. You can do that in your .vimrc like so:

noremap % v% 

Was this useful? Help us improve!

With your feedback, we can improve VimTricks. Click a link to vote: