How do I load Vim's optional built-in packages like matchit or editorconfig on demand?
Answer
:packadd {package}
Explanation
Vim ships with several useful packages in its opt/ directory that are not loaded by default. The :packadd command loads these optional packages on demand, either interactively or from your vimrc. This gives you extra functionality without third-party plugins — you just need to activate what is already there.
How it works
:packadd {package}— searches thepack/*/opt/{package}directories in yourpackpathand sources the package- The package becomes available immediately — its commands, mappings, and autocommands are loaded
- In your vimrc, use
packadd!(with a bang) to add the package toruntimepathwithout sourcing plugin scripts yet (deferred loading)
Example
Load the built-in matchit plugin to enable extended % matching for HTML tags, if/else blocks, and more:
" In your vimrc:
packadd! matchit
Now pressing % on an HTML <div> tag jumps to its closing </div>, and pressing it on if in many languages jumps to the matching endif or else.
Tips
- Run
:echo globpath(&packpath, 'pack/*/opt/*')to list all available optional packages on your system - Common built-in optional packages:
matchit(extended % matching),editorconfig(Vim 9+),comment(Neovim),termdebug(GDB integration) - Use
:packadd termdebugto get a full GDB debugging interface inside Vim without installing anything - Third-party plugin managers can install plugins into
opt/for lazy loading with:packadd