A question on .exrc while using vi

Bruce R. Larson ires at kaspar.UUCP
Wed Dec 5 05:33:25 AEST 1990


In article <13458 at chaph.usc.edu>, jeenglis at alcor.usc.edu (Joe English Muffin) writes:
> joshi at motcid.UUCP (Abhay B. Joshi) writes:
> >
> >I set up a .exrc in the current directory which looks like (2 lines):
> >	:g/the/ s//an/g
> >
> >Now I tried to do a 'vi text-file', I got a coredump! About 10 times.
> >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)
> 
> Just a guess:  I think that vi executes all the commands
> in .exrc BEFORE reading the file to be edited.  
> 
Joe is correct.  When vi starts it searches for initialization info:
1st)  from an EXINIT environment variable.  If EXINIT doesn't exist, then
      vi looks for a $HOME/.exrc and reads initialization info from that.
2nd)  from a .exrc in the current directory.
      [NOTE:  Some SysV3.2.* `vi's have a `:set noexrc' option that turns
      off sourcing of .exrc in the current directory.]


> I'm not sure what your actual application is, but you're better
> off mapping a macro to the substitute command.
> 
Here are some other things to try.

1) For simple changes, like the single global listed above, you can do this
        vi + ":g/the/ s//an/g" filenames
   or the modern equivalent
        vi -c ":g/the/ s//an/g" filenames

2) Use modelines.  This method is frowned upon.
   (!Modelines are considered dangerous and should be used with caution!)

   *) Put a .exrc file in the current directory containing `set modelines'.
   *) In the first or last 5 lines of the file in which you want the command
      executed, either 
	 vi:  `command' :
      or
	 ex:  `command' :
      You may want to place the above string inside of a comment, so your
      command would look like
	 /* vi: :g/the/ s//an/g :  /* modeline command */

In response to the coredump issue, I'm not sure why vi was dumping core,
but it looks as if you were trying to implement modelines in an illegal
way (i.e., modelines go in the file to be edited, not with the init info).

Bruce

-- 
Bruce R. Larson				| The drug problem in the US is so
Integral Resources, Milton MA		|  vast that we need to recognize that
Internet: ires.com!blarson at cs.umb.edu	|   it is primarily a social problem,
Uucp:     ..!cs.umb.edu!ires.com!blarson|    not a criminal problem.



More information about the Comp.unix.misc mailing list