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

How do I make % jump between custom bracket pairs like < and > in Vim?

Answer

:set matchpairs+=<:>

Explanation

By default, % jumps between (), [], and {} pairs. The matchpairs option controls which pairs are recognized. You can extend it with :set matchpairs+= to add custom pairs — useful when working with HTML/XML angle brackets, template delimiters, or any symmetric pair your language uses.

How it works

  • matchpairs is a comma-separated list of open:close pairs
  • Default value: (:),{:},[:]
  • += appends to the existing value without replacing it
  • Each pair is specified as open:close where both characters are single bytes

Add angle bracket support:

:set matchpairs+=<:>

Or add multiple pairs at once:

:set matchpairs+=<:>,«:»

To make this permanent, add it to your vimrc:

set matchpairs+=<:>

Example

In an HTML file with the cursor on <:

<section class="hero">

After :set matchpairs+=<:>, pressing % moves the cursor to the matching > at the end of the tag. Without the setting, % would jump to the { in class="hero" — or do nothing if the cursor is on <.

Tips

  • Use :set matchpairs? to inspect the current value
  • For filetype-specific pairs, use an autocmd or put the setting in ftplugin/:
    autocmd FileType html,xml setlocal matchpairs+=<:>
    
  • The matchit plugin (shipped with Vim/Neovim) extends % to multi-character pairs like if/end, do/done
  • matchpairs only works with single-byte characters; use matchit for keywords

Next

How do I open a specific buffer in a new split without navigating away from my current buffer?