Categories
Server

Unix: Fast Find and Replace in VIM

I configure a lot of files, and most of the time it’s all about copying an old config file, edit a few variables and save it.
Take for example a NGINX virtualhost file. You already have a website running and you want to run another site with similar configuration.

So you copy the existing virtualhost and give it a name, then opens it and want to change everyting that says “my-first-website” with “my-second-website”.

The following command is doing just that in one shot!

:%s/my-first-website/my-second-website/g

BOOM!

You have notice it’s using some regular expression quantifier “g” to tell VIM to replace all occurence of “my-first-website” with “my-second-website”.