3

I have the same text that I want to replace in multiple files (say, I'm updating version numbers in multiple files). Even using the command history to reuse commands, it sure is tedious to open each one, search and replace in it, and then save it. Can I do just all of this in one search and replace operation on all of these files?

Christopher Bottoms
  • 3,772
  • 6
  • 22
  • 33

1 Answers1

8

Let's say that you decided that you want to update the text use 5.008 to use 5.010 in multiple Perl script and Perl modules.

:arg *.pl       
:argadd *.pm
:argdo %s/use 5\.008/use 5\.010/ge | update

note that you need to escape '.', since it it's the wildcard for one character.

:arg *.pl fills the argument list with all of the files ending in .pl in the current directory.

:argadd *.pm adds all of the files ending in .pm to the argument list.

:argdo %s/use 5.008/use 5.010/ge | update Does the search and replace on each file in the argument list and saves each file for you.

See Search and Replace in Multiple Buffers for more details and variations.

Vin
  • 3
  • 3
Christopher Bottoms
  • 3,772
  • 6
  • 22
  • 33