Vi Tip of the Week: Find the matching brace

This is part of a series of tips on using Vi.  To see the complete series, click here.

A lot of the time when I’m working on a program, I want to quickly move my cursor to the matching brace.  For example, if I’m editing a nested if statement in C or Java, sometimes I’ll want to find the matching brace so that I know I’ve got my scope correct.  It’s very easy to do in vi — just place your cursor on the brace you want to match, then press the “%” key, and voila, you’re taken to the matching brace!

This works for parentheses and square brackets, too — it’s great for when you’re writing a long mathematical expression and you want to quickly check to make sure you’ve got your parentheses right!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.