DEV Community


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

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 ...

iggredible profile image
Igor Irianto Author

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

epse profile image
Stef Pletinck

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

bgturner profile image
Benjamin Turner

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


This will hit the "one two"


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