25 Nov, 2009, quixadhal wrote in the 21st comment:
Votes: 0
David Haley said:
Or, just use :bufdo to do it in all buffers immediately.


Ha! Thanks David!
About twice a year, I learn some new trick about vim. :)
25 Nov, 2009, JohnnyStarr wrote in the 22nd comment:
Votes: 0
David Haley said:
quixadhal said:
As kiasyn said….

vim *.c
qa:1,$s/send_to_char/sendch/g
:wn
a

Then if you had 20 files, 19@a to do the same search/replace on the rest of them.

Bam!

Or, just use :bufdo to do it in all buffers immediately.

vim *.c
:bufdo %s/send_to_char/sendch/g
:wa
:qa

No need to use macros in this instance.


When I try this, it gives me vims "No write since last change (add ! to override)"
It makes changes only in the first file act_info.c
25 Nov, 2009, David Haley wrote in the 23rd comment:
Votes: 0
Hmm, there's a setting to prevent that although I don't know it off the top of my head. In the meantime, try :bufdo!
I think the problem is that it's trying to switch buffers as part of :bufdo, and by default you can't do that if the buffer has changes.
25 Nov, 2009, Skol wrote in the 24th comment:
Votes: 0
David Haley said:
ruby -pe 'gsub(/send_to_char/, "sendch")' < *.c

This – and other similar examples given above in Perl – won't work because you can't redirect several files at once into the program and expect it to know how to break them back out into files again. You need to process them one at a time…


Actually they do work David? Although I strongly recommend backups of course.
// made 3 .txt files
// cat *.txt
bob.txt:
white and blue and red
blue and white and red

joe.txt:
red and blue
red and blue

yar.txt
blue and red
blue and red

perl -pi -e 's/blue/orange/g' *.txt

//yields: cat *.txt
bob.txt
white and orange and red
orange and white and red

joe.txt
red and orange
red and orange

yar.txt
orange and red
orange and red


Again, I always make backups first, but is there any inherent problem in using Perl like that?
I find it great for string replacement in places like say race within area files (if I don't want to do the step-by-step method in olc_save.c etc etc), also spells if they change on scrolls (rom originally, saves with the string), etc.
25 Nov, 2009, David Haley wrote in the 25th comment:
Votes: 0
Note the input redirection in the line I quoted – that's what causes the problem and what I referred to.
25 Nov, 2009, Tyche wrote in the 26th comment:
Votes: 0
Skol said:
Actually they do work David? Although I strongly recommend backups of course.
"ruby -pe 'gsub(/send_to_char/, "sendch")' < *.c"


Lke he said, it's the '<' that's the problem. Let Ruby/Perl process the files argument, instead of the shell.

You do that in your example that works…
perl -pi -e 's/blue/orange/g' *.txt
Skol said:
Again, I always make backups first, but is there any inherent problem in using Perl like that?


Perl and Ruby will make backups for you as the -i parameter accepts a suffix.
25 Nov, 2009, Skol wrote in the 27th comment:
Votes: 0
Ah, got it, thanks both!
20.0/27