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
matchpairsis a comma-separated list ofopen:closepairs- Default value:
(:),{:},[:] +=appends to the existing value without replacing it- Each pair is specified as
open:closewhere 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
autocmdor put the setting inftplugin/:autocmd FileType html,xml setlocal matchpairs+=<:> - The
matchitplugin (shipped with Vim/Neovim) extends%to multi-character pairs likeif/end,do/done matchpairsonly works with single-byte characters; usematchitfor keywords