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

How do I load shell search output into a window-local location list?

Answer

:lgetexpr systemlist('rg --vimgrep TODO %') | lopen

Explanation

When you want search results tied to only the current window, use :lgetexpr instead of :cgetexpr. This gives you the same parser-driven workflow as quickfix, but isolates results so another split can keep its own independent list. It is especially useful during refactors where each window is focused on a different subsystem.

How it works

  • systemlist('rg --vimgrep TODO %') runs ripgrep and returns each match line as a Vim list item
  • :lgetexpr parses those lines using errorformat and stores entries in the current window's location list
  • :lopen opens that list so you can step through with :lnext and :lprev

Because location lists are window-local, you avoid clobbering global quickfix state used by builds, tests, or another search session.

Example

src/service/user.ts:19:3: TODO validate email
src/service/user.ts:47:7: TODO normalize roles

After running the command, those matches appear in the current window's location list. In a second split, you can run a completely different :lgetexpr search and keep both result sets active at once.

:lnext
:lprev
:lclose

Tips

  • Keep :cgetexpr for shared, project-wide quickfix workflows; use :lgetexpr for per-window focus
  • If parsing looks wrong, tune errorformat to match your command output
  • Use %:p instead of % if your tool needs absolute paths

Next

How do I jump to a definition-style pattern match using Vim's define search?