A question on .exrc while using vi

Tom Christiansen tchrist at convex.COM
Tue Dec 4 17:07:18 AEST 1990


In article <5315 at graphite20.UUCP> joshi at motcid.UUCP (Abhay B. Joshi) writes:
:I couldn't find a newsgroup for vi questions, hence this intrusion.

Well, there is comp.editors, but you didn't know that.  

:I have a simple text-file containing the following text (3 lines): 
:
:	The goal:
:	All I am trying to do is replace the 'the's by 'an's.
:	That's all.
:
:I set up a .exrc in the current directory which looks like (2 lines):
:	:g/the/ s//an/g

What a funny place to put that command.  Plus you don't use colons
in your .exrc file.

:Now I tried to do a 'vi text-file', I got a coredump! About 10 times.

You know, one of the indications of insanity is doing the same
thing again and again and expecting different results. :-)

:Then I deleted the .exrc file and put the command in EXINIT.
:I got a coredump again. (No coredump if neither .exrc nor EXINIT exists)

:I don't think it's a memory problem. I use a SUN 4.0.3 with sunview with lots
:of programs running at the same time. I tried the above in a no-other-program-
:running mode too.

Um, that's kind of a peculiar way to do about it.  How come
you're putting it in your .exrc?  If this is something you want
to do automatically to a file, you could run sed or ex over it:

    sed 's/the/an/g' < file1 > file2 && mv file2 file1

or else

    ex - file <<EOEDIT
    %s/the/an/g
    x
    EOEDIT

Of course, you probably really want \<the\> instead so "bathe"
doesn't become "baan".  (That only works with ex though.)

Oh, and this should do the trick, too 

    perl -p -i -e 's/\bthe\b/an/g' file

The \b in perl is \< or \> in ex.  If you'd like the old 
file around as file.bak, then do this:

    perl -p -i.bak -e 's/\bthe\b/an/g' file

If, however, this is something you are expecting to do 
all the time when you're in the editor, you could make 
a macro to do it for you.  Put this in your .exrc, and 
don't put any blank lines there.

    map = :%s/\<the\>/an/g^M

Make your to put a real ^M in the file.  Now you just 
have to hit = to make the change.


--tom
--
Tom Christiansen		tchrist at convex.com	convex!tchrist
"With a kernel dive, all things are possible, but it sure makes it hard
 to look at yourself in the mirror the next morning."  -me



More information about the Comp.unix.questions mailing list