What is the location list and how does it differ from the quickfix list?
Answer
:lopen / :lnext / :lprev
Explanation
The location list is a per-window variant of the quickfix list. While the quickfix list is global (shared across all windows), every window can have its own independent location list. This makes it ideal for running multiple searches or lint checks in different splits without the results stomping on each other.
How it works
:lvimgrep /pattern/ **/*.pypopulates the current window's location list (compare with:vimgrepwhich populates the global quickfix list):lopenopens the location list window for the current window:lnext(:ln) jumps to the next entry in the location list:lprev(:lp) jumps to the previous entry:lfirstand:llastjump to the first and last entries:lclosecloses the location list window
Every command that has a quickfix equivalent has a location list counterpart — just replace the c prefix with l.
Example
You have two vertical splits open. In the left split, you search for TODO comments:
:lvimgrep /TODO/ **/*.js
:lopen
In the right split, you search for FIXME comments:
:lvimgrep /FIXME/ **/*.js
:lopen
Each window now has its own list of results. Pressing :lnext in the left window steps through TODO matches, while :lnext in the right window steps through FIXME matches. They don't interfere with each other.
Tips
- The location list is used by many plugins (like ALE, LSP clients) for per-buffer diagnostics — errors for one file don't clobber results for another
- Use
:ldo s/old/new/g | updateto run a substitution on every location list entry, analogous to:cdofor the quickfix list :lolderand:lnewernavigate between previous location lists for the same window, just as:colderand:cnewerdo for quickfix lists- Use
:lgrepwith an external grep program (configured viagrepprg) for faster searches on large codebases - Map location list navigation for convenience:
nnoremap ]l :lnext<CR>andnnoremap [l :lprev<CR> - A window's location list is destroyed when the window is closed — if you need persistent results, use the quickfix list instead
- You can have up to 10 stacked location lists per window (accessible with
:lolderand:lnewer)