Highlight matching bracket

Use Vim's showmatch feature to highlight the matching bracket upon insert.

In addition to jumping to the corresponding bracket or parenthesis with %, Vim has a little-known feature for showing corresponding parens when inserting.

Vim's showmatch feature might be useful for those writing code with many nested parentheses, such as Lisp. With :setshowmatch enabled, Vim enables a special bracket highlighting while in insert mode. After typing a paren, brace, or bracket, the cursor will automatically jump to the matching bracket ever so briefly. Just long enough for you to visually confirm which parenthesis you are closing. This can reduce the need to even use the % command to bounce to the bracket manually.

You can change the time the cursor spends there before bouncing back with matchtime.

Here’s how I use showmatch:

:set showmatch matchtime=3

This feature is best demonstrated so watch the brief screencast here. Notice how the insert-mode cursor jumps to the opposite bracket, highlighting the opposite side.

If you're working on a tiny screen, or on text with parens that span many lines, you may wish to have the screen scroll automatically when showmatch is enabled. Add this to your .vimrc:

inoremap } }<Left><c-o>%<c-o>:sleep 500m<CR><c-o>%<c-o>a inoremap ] ]<Left><c-o>%<c-o>:sleep 500m<CR><c-o>%<c-o>a inoremap ) )<Left><c-o>%<c-o>:sleep 500m<CR><c-o>%<c-o>a 

Was this useful? Help us improve!

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