Showing posts with label replace. Show all posts
Showing posts with label replace. Show all posts

05 March 2025

How To Search And Replace String Across Multiple Files in Vim

https://irian.to/blogs/how-to-search-and-replace-string-across-multiple-files-in-vim

 

Perform substitution with macros and repeat it

While recording a macro, perform substitution on one file, and repeat the macros across all args.

Assuming the same folder structure and args, here is how it is done:

qq                                          // start macro in q register
%s/stringToBeReplaced/replacementString/ge  // the e flag tells vim to not throw an error if there is no match
:wnext                                      //important. This is similar to `:next`, but it also writes the current file
q                                           // stop macro
999@q                                       //repeat this macros either 999 times or to remaining files.

That's it!