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

How do I search a project without overwriting the global quickfix list?

Answer

:lvimgrep /pattern/gj **/*.js | lopen

Explanation

When you already rely on the global quickfix list for compiler errors or another search, running :vimgrep can wipe that context. :lvimgrep solves this by writing results to a window-local location list instead, so each window can keep its own independent search set. This is especially useful during parallel refactors where one window tracks diagnostics and another tracks ad-hoc matches.

How it works

  • :lvimgrep /pattern/gj **/*.js runs a recursive grep and stores matches in the current window's location list
  • g finds all matches per line (not only the first)
  • j prevents jumping to the first hit immediately, preserving your current cursor location
  • | lopen opens the location list so you can review hits before changing anything

Example

Suppose quickfix still contains test failures and you need a focused search for deprecated API calls.

:lvimgrep /oldApiCall/gj **/*.js | lopen

Now navigate with :lnext and :lprev without touching global quickfix entries.

Tips

  • Use :lwindow instead of :lopen if you only want the list window when matches exist
  • :ldo applies commands per location entry, similar to :cdo for quickfix
  • Keep one split for quickfix (:copen) and another for location-list workflows to separate tasks cleanly

Next

How do I open a vertical diff between index and working tree for the current file in vim-fugitive?