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

How do I search only files in the argument list and inspect results in a location list?

Answer

:lvimgrep /{pattern}/j ## | lopen

Explanation

When you need to run focused searches across a curated set of files, the argument list is a strong scope boundary. Pairing it with :lvimgrep keeps results window-local, which avoids polluting the global quickfix list during parallel tasks. This is especially useful during refactors where each split has a different investigation context.

How it works

:lvimgrep /{pattern}/j ## | lopen
  • :lvimgrep runs Vim regex search and writes matches to the location list (not quickfix)
  • /{pattern}/ is your search regex
  • j adds matches without jumping away from your current cursor position
  • ## expands to all files currently in the argument list
  • | lopen opens the location list window immediately for review

Example

Suppose your argument list contains only files touched in a current change set:

api/auth.lua
api/session.lua
ui/login.lua

Running :lvimgrep /token\\|session/j ## | lopen gives a per-window hit list for those files only, rather than the entire project.

Tips

  • Build the argument list first with commands like :args **/*.lua or from shell expansion
  • Navigate matches with :lnext and :lprev
  • Keep different location lists in different windows for separate search threads

Next

How do I jump to the top of a file without creating a new jumplist entry?