How do I populate a window-local location list from the current file and open it immediately?
Answer
:lgrep /pattern/ % | lopen
Explanation
Quickfix is global, but sometimes you want a narrower search workspace tied to one window. :lgrep /pattern/ % | lopen builds a location list from the current file and opens it immediately, so you can iterate matches without disturbing any existing global quickfix workflow.
How it works
:lgrep /pattern/ %runs grep-like matching on the current file (%) and stores results in the window-local location list|chains a second Ex command in one linelopenopens the location list window so you can inspect and jump through matches
Because location lists are window-scoped, this is ideal when one split is dedicated to focused cleanup while another split keeps a separate quickfix task active.
Example
In a large file, find all TODO markers without replacing your project-wide quickfix results:
:lgrep /\<TODO\>/ % | lopen
Now use :lnext and :lprev to move through hits, or jump directly from the location list buffer.
Tips
- Use
:lgrepaddto append additional patterns to the same location list. :lwindowopens the location list only when there are entries, which is useful in mappings.- Keep global quickfix (
:grep,:vimgrep) for cross-file work and location lists for in-window, task-specific searches.