[comp.editors] Yet another vi question

djm408@tijc02.UUCP (David Marks ) (09/21/88)

How does one enter vi to edit a particular file, and upon entry pull
in a template to use as a fill in the blank form? For example, let us say I
want to create a report called myreport, and the standard template is stored
in template.rpt. I tried the following (and variations thereof)

     vi +'r template.rpt' myreport

It thinks that I want to edit two files (template.rpt, and myreport) and says
so, but somehow while building the buffer it core dumps! I also tried putting
"r template.rpt" in the EXINIT environment variable and/or in the .exrc file. It
still doesn't work. 

I would like to do this so that I can automate a reporting system we use for
software modifications/bugs by giving developers vi to edit the report while
forcing them to use the template (no flames here please! They can always
erase the template if they don't want it with ":1,$d". :-) )


-----------------------------------------------------------------------------
         #include <standard/disclaimer.h>

         LIFE IS NOT A MALFUNCTION! - Number 5 

Pony Express:                      |    Electric Avenue:
=============                      |    ================
                                   |
David J. Marks                     |    ...!mcnc!rti!tijc02!djm408
Texas Instrument                   |
M/S 3520                           |    Ma Bell:
Erwin Highway/P. O. Drawer 125     |    ========
Johnson City, TN. 37605            |    
                                   |    615-461-2074

roger@homxc.UUCP (Another Technical Editor) (09/23/88)

In article <260@tijc02.UUCP>, djm408@tijc02.UUCP (David Marks         ) writes:
> How does one enter vi to edit a particular file, and upon entry pull
> in a template to use as a fill in the blank form? (etc. etc.)

Write a small shell program:

cp template.rep $1;vi $1

and use this program instead of spelunking through vi's feature set. 

> David J. Marks                     |    ...!mcnc!rti!tijc02!djm408

Roger Tait                             ..att!homxc!roger
AT&T Bell Labs Technical Publications        Holmdel, NJ

(-; (-; "Where never is heard a discouraging word,
         and the skies are not cloudy all day." :-) :-)

boykin@multimax.Encore.COM (Joe Boykin) (09/23/88)

In article <260@tijc02.UUCP> djm408@tijc02.UUCP (David Marks         ) writes:
>How does one enter vi to edit a particular file, and upon entry pull
>in a template to use as a fill in the blank form? For example, let us say I
>want to create a report called myreport, and the standard template is stored
>in template.rpt. I tried the following (and variations thereof)
>
>     vi +'r template.rpt' myreport

This is close, but not quite.  Try the following:

	vi "+:r template.rpt" myreport

----

Joe Boykin
Encore Computer Corp

UUCP: encore!boykin
ARPA: boykin@multimax.arpa

ccea3@rivm.UUCP (Adri Verhoef) (09/24/88)

In article <260@tijc02.UUCP> djm408@tijc02.UUCP (David Marks         ) writes:
>How does one enter vi to edit a particular file, and upon entry pull
>in a template to use as a fill in the blank form? For example,
>
>     vi +'r template.rpt' myreport

Try this:

	vi +"r'template.rpt'" myreport


		Cheers!
		Adri.

fyl@ssc.UUCP (Phil Hughes) (09/24/88)

In article <260@tijc02.UUCP>, djm408@tijc02.UUCP (David Marks         ) writes:
> How does one enter vi to edit a particular file, and upon entry pull
> in a template to use as a fill in the blank form? For example, let us say I
> want to create a report called myreport, and the standard template is stored
> in template.rpt. I tried the following (and variations thereof)

>      vi +'r template.rpt' myreport

We do something similar.  From our customer file (which is in the Progress
database system) we have a key which dumps you in vi with the boiler plate
of a letter and the cursor on the Dear ___ line.

The way I did it (which is written in Progress but could be in a shell
script) was to copy the boiler plate file to the new file and then enter
vi on the new file with +/^Dear/ 
Seems like a shell script like this would solve your problem.

Phil Hughes, SSC, Inc. P.O. Box 55549, Seattle, WA 98155  (206)FOR-UNIX
    uw-beaver!tikal!ssc!fyl or uunet!pilchuck!ssc!fyl or attmail!ssc!fyl

-- 
Phil    uunet!pilchuck!ssc!fyl 

djm408@tijc02.UUCP (David Marks ) (10/05/88)

I recently posted the following to this newsgroup:

>How does one enter vi to edit a particular file, and upon entry pull
>in a template to use as a fill in the blank form? For example, let us say I
>want to create a report called myreport, and the standard template is stored
>in template.rpt. I tried the following (and variations thereof)
>
>    vi +'r template.rpt' myreport
>
>It thinks that I want to edit two files (template.rpt, and myreport) and says
>so, but somehow while building the buffer it core dumps! I also tried putting
>"r template.rpt" in the EXINIT environment variable and/or in the .exrc file. 
>It still doesn't work. 
>
>I would like to do this so that I can automate a reporting system we use for
>software modifications/bugs by giving developers vi to edit the report while
>forcing them to use the template (no flames here please! They can always
>erase the template if they don't want it with ":1,$d". :-) )

-------------------------------------------------------------------------------
Most responded with variations of 

       vi +'r template.rpt' myreport

including changing the single quotes to double quotes, or adding ":0" in
front of the "r" command, etc. None of these work on the system I am using:
SYSTEM V Rel. 2.2 ported to the VAX8600 by UNIQ DIGITAL. If one of these
variations works on yours then you have a different vi than the one we use
here.

-------------------------------------------------------------------------------

A few suggested I copy the template over to a file called "myreport" and 
then edit it, or read in the template from the ex command line at the bottom 
of the vi screen. I am trying to avoid this so that I can run vi from a program
with a fork/exec automatically. If our developers have to remember to read in 
the template when they enter vi in the reporting system, they will most likely 
forget and not use it. We are trying to standardize our bug reports.

-------------------------------------------------------------------------------

One person actually knew what he was saying and told me that this cannot be 
done with vi unless the target file "myreport" already exists (even if it is
blank :-) ). This appears to be true on our system.

-------------------------------------------------------------------------------

Thanks to all that responded. It appears that what I want to do cannot be done
with vi (unless I copy the template over to the target file or create a blank
target first). I consider this a serious bug (I'm not sure if this is a design
or implementation bug), as all manuals and books that I have read about
vi claim that it can run ANY ex command on entry to vi. Not one mentions any
exceptions.

-----------------------------------------------------------------------------
 #include <standard/disclaimer.h>  |  LIFE IS NOT A MALFUNCTION! - Number 5 
    ____  ____ _  _  __ ____     ____    _  _  ____  ____   _  _  ____
    /  / /   /  | /  /  /  /      /     //_// /   / /   /   / /  /___
   /  / /---/   |/  /  /  /   /  /     /   / /---/ /---\   / \      /
  ~~~~ ~   ~    ~  ~~ ~~~~    ~~~  ~  ~   ~ ~   ~ ~    ~  ~  ~  ~~~~

Pony Express:                      |    Electric Avenue:
=============                      |    ================
David J. Marks                     |    ...!mcnc!rti!tijc02!djm408
Texas Instrument                   |
M/S 3520                           |    Ma Bell:
Erwin Highway/P. O. Drawer 125     |    ========
Johnson City, TN. 37605            |    615-461-2074

bell@bell_hop.uucp (John T. Bell) (10/07/88)

Your vi seems to be broken. I have tried a number of the suggestions
on various vi's all with success. (Including Xenix 2.2, and DOS). 
However I could not get vi to return to the top of the file, after
including the template file. (ie; exec more than one ex command.)
However a simple shell script may solve your problem.
Something like this might work for you...

# rem if file exists and contains data then just edit it.
if test -s %1
	vi %1
else
# else give it the template and edit it.
	cat template >%1
	vi %1
fi

If you really wanted to be creative you could replace the reference
to vi with a reference to the editor variable, and let the user use
the editor of his/her choice. I am not aware of any problems with
forking to a shell script so this may be your best solution.

marty@homxc.UUCP (M.B.BRILLIANT) (10/12/88)

Sorry I came in late with this, but my curiosity was not aroused until
I noticed that all gurus were stumped.

There is a way to get vi to read a template before editing the file.
The quirk is that vi will not execute the '+command' argument unless
it successfully reads the file.  I tried that with a simple '+map x p'
argument, and the mapping did not take effect unless vi also received
a file argument, and the named file already existed.

The only excuse I could find for this quirk is that the manual page
explains the +command argument by saying "The specified ex command is
interpreted before editing begins."  If no file is read in, there is
nothing to edit, so editing never "begins," and +command is skipped.

So you will not be able to name a new nonexistent file as the file
argument for vi, and use the +command argument to read a template.

The solution is to name the template file in the vi command, and use
the +command argument to ask vi to change the file name.

Thus (on the system I am working on) the command
	"vi '+r template' newfile"
does not work, but the command
	"vi '+f newfile' template"
does exactly what you want.

						Marty
M. B. Brilliant		houdi!marty1, homxc!marty

gast@lanai.cs.ucla.edu (David Gast) (10/13/88)

In article <270@tijc02.UUCP> djm408@tijc02.UUCP (David Marks         ) writes:
>I am still getting responses to my question on entering vi with a blank
>template. Most of you are missing the point I was trying to make and why I
>asked the question in the first place.
>
>        around a problem, I usually am curious enough to want an
>        answer to why the original solution would not work.

It seems to be a ``feature.''  But a solution does exist, see below.

>
>     2. I was trying to avoid copying the template file to the report
>        before editing it. Doing this from a program means that I have
>        to invoke a shell which creates another process that really should
>        not be needed.

No need to invoke the shell or to create any new processes if you are
writing a C program.  Just use the function calls described in the
manual. I use BSD so I do not know the precise names you will have to
use for System V.

>
>     3. I feel that vi should be able to this. No manual I have read
>        (no flames on UNIX manuals and books please :-) ) even comes
>        close to explaining why this might not work. All claim that
>        ANY ex command can be executed on entry to vi, including those
>        that take arguments; most show examples of the "set" command.

I just checked one.  It says that "most" or "many" (I forget which one)
commands work.  It does not say that all work.  It is, however, either
a bug or a bad feature that not all do not work.

>
>Those of you that thought that my vi is damaged, should know that we are using
>the same vi that is distributed by AT&T with System V rel. 2.2, and thus AT&T
>must have a damaged vi.

As you probably know, AT&T did not write vi.  There is nothing that says
that Berkeley or AT&T never write code with bugs or features.

>I resent the attitude that some of you took trying to explain to me how to use
>shell scripts to solve my problem.

Please try to excuse us.  How many cpu cycles do you figure you will save
by not using a shell script?  How many CPU cycles have been spent sending
your message and all of the replies across the net?  Is it a positive
number or would have it been better to do it in a shell script to begin
with?  In the Bourne shell or Korn Shell, you could have done
	> file
to create a file without starting any extra processes.  The shell works
great for many programs.

There is a way to do exactly what you want to do and all from within
vi.  If I understand, you want to be able to invoke vi, with something
like ``vi file'', where file does not exist, but when vi is called a template
is copied into file automatically.

Since you resent all suggestions, here is my offer.  Send me a $100
cashiers check and I will send you the solution.  It only uses vi.
I do not claim that it is better than the above suggestions, only
that it works.

David Gast
1446 Federal Avenue #A
Los Angeles, CA 90025
gast@cs.ucla.edu

{uunet,ucbvax,rutgers}!{ucla-cs,cs.ucla.edu}!gast