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
:ldoto run a command on each location list entry (like:cdofor quickfix) - Combine with splits: search different patterns in different windows
:lvimgrepwon't overwrite your quickfix list from:makeor:grep- Use
[land]l(with unimpaired.vim-style mappings) for faster navigation