[lug] Little vim trick, editing multiple files
tkil at scrye.com
Thu Dec 1 15:42:31 MST 2005
>>>>> "Tkil" == Tkil <tkil at scrye.com> writes:
Tkil> I tend to reach for perl for this sort of thing:
Tkil> perl -i~ -pwe 's:/old/path:/new/path:g' files...
Tkil> Quick version of the arguments:
Tkil> -i~ edit "in-place", create backup if changed with "~" suffix
Tkil> -p print every line after applying the script
Tkil> -w print warnings
Tkil> -e script is given on command line in next arg, not in first file
>>>>> "Daniel" == Daniel Webb <lists at danielwebb.us> writes:
Daniel> Ah, but your Perl solution misses one essential feature of the
Daniel> Vim solution: interactiveness.
In my own defense, the original solution was non-interactive -- as you
yourself point out:
Daniel> With the Vim solution given, you just add the "c" flag
Regarding interactivity, I figure that if I'm going to be brute-
forcing a bunch of edits, I will know that they all need to be changed
beforehand. Or I'll replace constants with symbolic names, then use
the "grep" or "grep-find" commands in emacs to review those changes.
And just to be complete, the emacs equivalent of this construct is
probably 'dired-do-tags-query-replace' to hit everything in a dired
buffer that is marked. Or one could use the 'grep-find' command
directly, and just page through each "hit"; this is something that I
use pretty often these days, now that I'm slagging through Java code.
(Why is Java so much worse for this sort of file crawling? Because of
the enforcement of "the path is the package" convention; add that to a
few CVS and build directories; and qualify everything with your domain
and business unit. Suddenly you're dealing with:
Just yesterday I did something like this (inside emacs):
M-x grep-find RET
find . -name '*.java' -print0 | xargs -0 grep -n -e 'new SAX.*Exception'
Then I could use 'next-error' to visit each file in turn and examine
that section of code.
Daniel> It takes a dedicated week or so to properly learn Vim. I have
Daniel> no idea how long Emacs takes, but I assume it's similar.
I'll agree that it takes a dedicated week to start rewiring your
fingers and to learn the basics. But I'm still "learning emacs" after
nearly 20 years.
More information about the LUG