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

How do I use the location list for per-window navigation?

Answer

:lnext and :lprev

Explanation

The location list is a per-window alternative to the quickfix list. Each window can have its own location list, making it ideal for window-specific search results.

How it works

  • :lnext (or :lne) moves to the next location list entry
  • :lprev (or :lp) moves to the previous entry
  • :lopen opens the location list window
  • :lvimgrep populates it with search results

Example

:lvimgrep /TODO/ %
:lopen
:lnext
:lnext

This searches the current file for TODO comments and navigates through them.

Tips

  • Each window has its own location list; the quickfix list is global
  • :lfirst and :llast jump to the first and last entries
  • :llist shows all entries
  • Useful when you want different search results in different splits

Next

How do you yank a single word into a named register?