How do I make the % key jump between custom bracket pairs like < and >?
Answer
:set matchpairs+=<:>
Explanation
By default, % jumps between matching (), {}, and [] pairs. The matchpairs option controls which delimiter pairs are recognised. Using += appends a new pair without removing the defaults, so you can add any ASCII delimiter pair you need.
How it works
matchpairsis a comma-separated list ofopen:closepairs- Default value:
(:),{:},[:] :set matchpairs+=<:>appends<:>to the list- After this, pressing
%on<jumps to the matching>and vice versa
Each pair is written as open:close using any two distinct ASCII characters.
Example
With :set matchpairs+=<:> active, given:
<template v-for="item in items">
Placing the cursor on < and pressing % jumps to the closing > at the end of the tag.
Tips
- Add multiple pairs at once:
:set matchpairs+=<:>,«:» - For filetype-specific pairs, put the setting in
~/.vim/ftplugin/{filetype}.vimor use anautocmd:autocmd FileType html setlocal matchpairs+=<:> - The built-in
matchitplugin extends%further to handle multi-character pairs likeif/endin Ruby ordo/endin shell scripts::packadd matchit - To view your current pairs:
:set matchpairs?