Find and Replace text or string in Vi
Posted by raxsoJul 12
This will replace all occurrences of match_pattern in the file
:g/match_pattern/s//replace_string/g
ex: you want to change all occurrences of an allow rule in your vhost file and comment it out
Allow from 192.168.0.1 to #Allow from 192.168.0.1
:g/Allow from/s//#Allow from/g
This command will find and replace the string that matches the condition.
alternatively, you can use ‘ : ‘ instead of ‘ / ‘ to make path (/) slashes easier to manage (no escape (\) character needed)
:g:match_pattern:s::replace_string:g
Like this blog? Why not buy me a cup of coffee?




![[hackers black book]](http://raxso.net/images/hbb-ani-misuse.gif)





Leave a Reply