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

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/ **/*.py populates the current window's location list (compare with :vimgrep which populates the global quickfix list)
  • :lopen opens 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
  • :lfirst and :llast jump to the first and last entries
  • :lclose closes 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 | update to run a substitution on every location list entry, analogous to :cdo for the quickfix list
  • :lolder and :lnewer navigate between previous location lists for the same window, just as :colder and :cnewer do for quickfix lists
  • Use :lgrep with an external grep program (configured via grepprg) for faster searches on large codebases
  • Map location list navigation for convenience: nnoremap ]l :lnext<CR> and nnoremap [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 :lolder and :lnewer)

Next

How do I edit multiple lines at once using multiple cursors in Vim?