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

How do I lazy-load cfilter from vimrc without interrupting startup when it is unavailable?

Answer

:packadd! cfilter

Explanation

If you share a Vim config across machines, optional plugins can cause noisy startup behavior when a package is missing. :packadd! solves this by attempting to load a package silently, so your config remains portable. This is useful for built-in optional runtime plugins like cfilter that you only need in quickfix-heavy workflows.

How it works

:packadd! cfilter
  • :packadd loads an optional package from pack/*/opt/
  • ! makes the command silent when the package is not found
  • cfilter provides :Cfilter and :Lfilter for narrowing quickfix/location lists

Place this near mappings that depend on :Cfilter, so your setup works where available and degrades cleanly where it is not installed.

Example

In your vimrc:

packadd! cfilter
nnoremap <leader>qe :Cfilter /ERROR/<CR>

On systems with cfilter, <leader>qe filters quickfix entries to errors. On systems without it, startup still succeeds and you can guard the mapping separately if needed.

Tips

  • Prefer :packadd! for optional, environment-specific tooling
  • Use plain :packadd when missing packages should fail loudly during setup

Next

How do I insert a register in Insert mode without reindenting each inserted line?