I know that the incsearch
setting controls how search in vim highlights as you type. I would like to have the same incremental search and highlight when using the replace command (:%s/foo/bar/
)
The easiest way to do that is to do a search like normal, using 'incsearch'
to help ensure the pattern is matching what you want. Once you've got that nailed down, you can either
:%s//bar/
. When there's no specified search pattern, the current value of the /
register is used, which will be the search you just did.:s
command using Ctrl+r/ (see :help c_ctrl-r
) or Ctrl+rCtrl+o/ (if the search contains control characters, like ^H
). This is useful if you want to make some final tweaks to the pattern or if you want to have it in your command history so you can reuse it even after performing another search.You could add c
at the end of your command like that:
:%s/foo/bar/c
It will walk through all the instances of foo
and ask for your confirmation (that's what the c
stands for) before changing it to bar
.
It's not exactly what you are after though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With