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

How do I make % jump between custom character pairs like < and >?

Answer

:set matchpairs+=<:>

Explanation

By default, % jumps between matching (), [], and {} pairs. Adding entries to matchpairs extends this to any pair of characters you choose, which is useful when working with languages that use <> for generics, template arguments, or HTML-like syntax.

How it works

  • matchpairs is a comma-separated list of open:close character pairs
  • The += operator appends to the existing value instead of replacing it
  • After :set matchpairs+=<:>, pressing % on a < jumps to the matching > and vice versa
  • This is purely character-based — it does not understand HTML tag names (for that, use matchit)

Example

In a C++ template:

std::vector<int>

With the cursor on <, pressing % jumps to >. Without the custom pair, % would not recognize these.

Add multiple pairs in one command:

:set matchpairs+=<:>,|:|

Tips

  • Put this in your vimrc (without the colon) for persistence: set matchpairs+=<:>
  • To view the current value: :set matchpairs?
  • The matchit plugin (bundled with Vim/Neovim as an optional package) extends % further to match language keywords like if/end, HTML tags, etc.
  • Enable matchit with: :packadd matchit (Neovim) or runtime macros/matchit.vim (Vim)

Next

How do I set a bookmark that persists across different files and Vim sessions?