DEV Community

loading...

Discussion on: How To Search And Replace String Across Multiple Files in Vim

Collapse
gypsydave5 profile image
David Wickes

Is there another trick that you use to do global search and replace?

sed -i -e 's/original/replacement/' fileone.txt filetwo.txt ...

Collapse
iggredible profile image
Igor Irianto Author

This is a good alternative too! Combined with grep it can do powerful things :)

Collapse
epse profile image
Stef Pletinck

If only there was some sensible way of replacing a multi-line search string.

Collapse
bgturner profile image
Benjamin Turner

Vim's regex can do this with a newline character. So having a buffer like:

one
two
three

This will hit the "one two"

:%s/one\ntwo/replaced/

In some cases, depending on the line endings, you might need to include the carriage return: \r

I almost never get the search string right the first time, so using the highlight search and incremental search settings is really helpful.

:set hls incsearch

All this is super powerful, but I'll leave it to you to determine if it's sensible. :)

Thread Thread
epse profile image
Stef Pletinck

Oh yeah that's perfectly sensible and something I knew about, I was more talking about the sed approach