VI: search and replace in multiple files

If you have opened multiple files, you can search and replace a text in all files by doing:

:argdo %s/search/replace/gec | update

This will replace all occurences of ‘search’ by ‘replace’, asking you for confirmation before doing each replacement. The e in /gec is used to supress error messages in case that the search string was not found in a file

(reference: (12/04/2013) James O’Beirne: Search and replace across many files in vim)

Leave a Reply

Your email address will not be published. Required fields are marked *