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

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 list
  • systemlist(...) runs ripgrep and returns output as a Vim list of lines
  • shellescape(expand('%:p')) safely passes the current file path to the shell command
  • 'efm': '%f:%l:%c:%m' tells Vim how to parse file:line:col:message entries

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 TODO for any pattern you are auditing
  • Use :lwindow instead of :lopen to open only when matches exist
  • Prefer this over quickfix when each window needs independent navigation state

Next

How do I allow block selections past end-of-line while still permitting one-char past EOL cursor movement?