How do I enable matchit so % jumps between if/else/end style pairs?
Answer
:packadd matchit<CR>
Explanation
The default % motion is great for simple delimiters, but many code structures use semantic pairs like if/else/endif, try/catch, or HTML tags. Vim ships with the matchit plugin, which extends % to understand these richer pairs. Loading it on demand is an efficient intermediate trick when you want smarter structural navigation without committing to a full plugin manager setup.
How it works
:packaddloads an optional package from Vim's runtime packagesmatchitis the built-in package name- after loading,
%can jump across language-aware match groups instead of only single-character delimiters
This keeps your movement commands native and fast while dramatically improving navigation in template-heavy or block-heavy files.
Example
Given:
if condition
echo 'a'
else
echo 'b'
endif
With cursor on if, press % after :packadd matchit and Vim can jump to else or endif depending on context.
Another common case is HTML/XML, where % can jump between opening and closing tags once matchit is active.
Tips
- Put
packadd matchitin your config if you want this behavior always enabled. - If
%behavior seems unchanged, confirm filetype detection is active because many match rules are filetype-aware.