[lug] Little vim trick, editing multiple files

Daniel Webb lists at danielwebb.us
Thu Dec 1 13:57:35 MST 2005

On Wed, Nov 30, 2005 at 06:59:06PM -0700, Tkil wrote:

> I tend to reach for perl for this sort of thing:
>   perl -i~ -pwe 's:/old/path:/new/path:g' files...
> Quick version of the arguments:
>   -i~  edit "in-place", create backup if changed with "~" suffix
>   -p   print every line after applying the script
>   -w   print warnings
>   -e   script is given on command line in next arg, not in first file

Ah, but your Perl solution misses one essential feature of the Vim solution:
interactiveness.  With the Vim solution given, you just add the "c" flag at
the end, and now you can see the page of code where the replace is about to
happen, and scroll through it, and decide whether or not to do the replace,
among other options.  This makes all the difference in the world when you're
talking about several hundred replaces over hundreds of files.  I use this
construct nearly every day.

I actually wrote this list back in August 2002 (yay Mairix) wanting to do
exactly this.  I never found a decent solution until I learned Vim.  So for
any newbie coders on the list: learn a real editor NOW.  Vim or Emacs.  Do it!
If you spend any serious time editing code, you'll kick yourself for every day
you put it off.  It takes a dedicated week or so to properly learn Vim.  I
have no idea how long Emacs takes, but I assume it's similar.  I can't even
imagine going back to something like Kdevelop now.

More information about the LUG mailing list