How do I run a replacement only over the current window's location-list matches?
Answer
:ldo s/foo/bar/ge | update\<CR>
Explanation
:ldo is one of the most effective ways to perform targeted, multi-file edits without touching unrelated text. Instead of running a blanket project-wide substitution, you can first build a location list (for example with :lvimgrep) and then run your replacement only on those hits. This gives you quickfix-style batch power, but scoped to one window's workflow.
How it works
:ldo s/foo/bar/ge | update
:ldoexecutes a command for each entry in the current window's location lists/foo/bar/geperforms substitution at each locationgreplaces all matches on the lineesuppresses "pattern not found" errors so the batch run keeps going| updatewrites only buffers that changed
Example
You search for legacy calls in one feature area:
:lvimgrep /OldApiCall/j src/feature_a/**/*
:lopen
Then apply a controlled migration:
:ldo s/OldApiCall/NewApiCall/ge | update
Only location-list hits in that window are processed, which helps avoid accidental edits outside the scope you reviewed.
Tips
- Use
:lfirst,:lnext, and:llto inspect entries before batch editing - Prefer
:ldowhen you need window-local scope; use:cdowhen you truly want global quickfix scope - Add
:set hiddenin long sessions if you frequently hop through many buffers