How do I use the location list instead of the quickfix list to have per-window grep results?
Answer
:lgrep {pattern} {files}
Explanation
The location list is a per-window counterpart to the global quickfix list. Each window can have its own independent location list, making it possible to have multiple simultaneous grep searches open in different windows without overwriting each other. The full location list command set mirrors the quickfix commands but starts with l.
How it works
:lgrep {pattern} {files}— search and populate the current window's location list:lopen/:lclose— open/close the location list window for the current window:lnext/:lprev— navigate to the next/previous location list entry:ll {N}— jump to entry number N in the location list:lfirst/:llast— jump to the first/last entry
Key difference from quickfix:
| Feature | Quickfix | Location List |
|---|---|---|
| Scope | Global (shared) | Per-window |
| Commands | :grep, :cnext |
:lgrep, :lnext |
| Window | :copen |
:lopen |
| Filled by | :make, :vimgrep |
:lmake, :lvimgrep |
Example
Open two vertical splits, each with a different search:
:vsplit
:lgrep 'TODO' **/*.go
:wincmd p
:lgrep 'FIXME' **/*.go
Now each window has its own location list. Switching windows and using :lnext/:lprev navigates that window's results independently.
Tips
- Many plugins (like LSP diagnostics) populate the location list rather than quickfix for this per-window isolation
:ldo {cmd}runs an Ex command on every location list entry, the per-window equivalent of:cdo- Use
:lwindowto automatically open the location list only if it has entries (quieter than:lopen)