How do I gather all matches from the current file into a location list without moving the cursor?
Answer
:lvimgrep /pattern/j %
Explanation
When you want a searchable list of matches without leaving your current editing context, :lvimgrep is a strong alternative to regular / navigation. It writes matches into the window-local location list, so you can inspect and jump through results with :lopen, :lnext, and :lprev without polluting the global quickfix list. The /j flag is the key detail: it keeps Vim from jumping to the first hit immediately.
How it works
:lvimgrepperforms a Vim regex search and stores results in the location list for the current window./pattern/is your search regex.jtells Vim to collect matches but stay where you are (no first-match jump).%limits the search to the current file.
Example
Suppose your file has multiple TODO comments and you want to triage them in one pass:
:lvimgrep /TODO/j %
:lopen
You keep your cursor position, open the match list, and then move deliberately through each item:
:lnext
:lprev
Tips
- Use
:lwindowinstead of:lopenif you only want the window to open when matches exist. - Prefer
:lvimgrepover:vimgrepwhen you want per-window isolation during focused refactors.