Neovim: Global search and replace
Posted on:
This is notoriously cumbersome in (Neo)vim.
For a quick experience you will need Telescope.
First, you need to search the occurrencies you want to replace. Run :Telescope live_grep
and type what you need. Remember to use rg
syntax for optimal filtering.
When you are satisfied with the results, press CTRL-Q
to add the results to the quickfix list (:h Quickfix
).
Ultimately, type :cdo s/gr/ep/gc
where s/gr/ep/gc
is the typical, perl-based, search syntax inside vim. Use gc
to give confirmation for every item, remove c
if you feel very sure. I am not sure if g
is actually needed but we’ll leave it to make sure.