How do I populate a window-local location list for only the current file using ripgrep output?
Answer
:call setloclist(0, [], 'r', {'title': 'TODO current file', 'lines': systemlist('rg --vimgrep TODO ' . shellescape(expand('%:p'))), 'efm': '%f:%l:%c:%m'})
Explanation
For focused review work, a window-local location list is often better than global quickfix. This command rebuilds the current window's location list from rg --vimgrep output for just the active file, giving you precise, disposable navigation scope.
How it works
setloclist(0, [], 'r', {...})targets the current window (0) and replaces ('r') its location listsystemlist(...)runs ripgrep and returns output as a Vim list of linesshellescape(expand('%:p'))safely passes the current file path to the shell command'efm': '%f:%l:%c:%m'tells Vim how to parsefile:line:col:messageentries
This pattern shines when you want separate work contexts per split, such as one window for TODO triage and another for test failures.
Example
:call setloclist(0, [], 'r', {'title': 'TODO current file', 'lines': systemlist('rg --vimgrep TODO ' . shellescape(expand('%:p'))), 'efm': '%f:%l:%c:%m'})
:lopen
You can then jump with :lnext and :lprev without touching the global quickfix list.
Tips
- Swap
TODOfor any pattern you are auditing - Use
:lwindowinstead of:lopento open only when matches exist - Prefer this over quickfix when each window needs independent navigation state