Xref: utzoo comp.unix.misc:675 comp.unix.questions:27363 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!texsun!letni!mic!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.misc,comp.unix.questions Subject: Re: A question on .exrc while using vi Keywords: exrc vi Message-ID: <109800@convex.convex.com> Date: 4 Dec 90 06:07:18 GMT References: <5315@graphite20.UUCP> Sender: usenet@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Followup-To: comp.unix.misc Organization: CONVEX Software Development, Richardson, TX Lines: 70 In article <5315@graphite20.UUCP> joshi@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 < 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/\/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@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