Jump to matching bracket

3.4
(363)

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 bouncing 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% 

How useful was this tip?

Average rating 3.4 / 5. Vote count: 363

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts