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

How do I search across files with lvimgrep and keep results in a window-local location list?

Answer

:lvimgrep /pattern/j **/* | lopen

Explanation

Quickfix is great, but it is global. In split-heavy sessions you often want per-window search results so one task does not overwrite another. :lvimgrep gives you that by populating the location list for the current window, and :lopen shows it immediately. This is a strong pattern when you run parallel investigations in different windows.

How it works

  • :lvimgrep /pattern/j **/* searches files recursively and stores matches in the current window's location list
  • The j flag includes multiple matches per file instead of only the first
  • | lopen opens the location list window right away
  • Navigation uses location-list commands (:lnext, :lprev, :lfirst, :llast) without touching global quickfix state

Example

From your project root, run:

:lvimgrep /TODO\\|FIXME/j **/*.lua | lopen

Your location list fills with matching lines in Lua files:

lua/server/init.lua:42: TODO: split router setup
lua/ui/panel.lua:10: FIXME: debounce redraw

You can inspect these with :lnext and keep your main quickfix list intact for a different task.

Tips

  • Prefer :lgrep/:lvimgrep when context is local to one window
  • Use :lwindow instead of :lopen if you only want the window when there are entries
  • If your glob is expensive, narrow it (**/*.go, src/**/*.ts) to keep searches fast

Next

How do I run a one-off macro without recording by executing keystrokes from an expression register?