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

How do I search across files using the location list instead of quickfix?

Answer

:lvimgrep /pattern/ %

Explanation

While :vimgrep populates the global quickfix list, :lvimgrep uses the window-local location list instead. This lets each window maintain its own independent search results, which is essential when you need to compare search results side-by-side or keep a quickfix list intact.

How it works

  • :lvimgrep /pattern/ {files} — searches files and fills the location list
  • :lopen — opens the location list window
  • :lnext / :lprev — navigate between matches
  • The location list is per-window, so each split can have different results

Example

:lvimgrep /TODO/ **/*.py
:lopen
Location list shows:
file1.py|10| # TODO: refactor this
file2.py|25| # TODO: add tests
file3.py|42| # TODO: fix bug

Tips

  • Use :ldo to run a command on each location list entry (like :cdo for quickfix)
  • Combine with splits: search different patterns in different windows
  • :lvimgrep won't overwrite your quickfix list from :make or :grep
  • Use [l and ]l (with unimpaired.vim-style mappings) for faster navigation

Next

How do I return to normal mode from absolutely any mode in Vim?