[comp.unix.questions] Two vi questions.

saroff@jvncf.UUCP (Steve Saroff lac00001) (09/08/89)

I have two questions.

1) Can you tell me why when I try to read in a file with the
":r" command, it barfs for long path names?

2) Is there any quick and dirty way of inserting a character(s) say
at the front of lines (e.g. quick commenting out of 20 lines of code)

Thanks


-- 
			SzS
Dr. S.Z. Saroff
John von Neumann National Supercomputer Center   internet: saroff@jvncf.csc.org
665 College Road East, P.O. Box 3717                       saroff@jvncc.csc.org
Princeton, NJ 08543   (609) 520-2000             bitnet:   saroff@jvncc
               
                o o
                (_)____o
~~~~~~~~~~~~~~~~~(_____)~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  oo oo          The Bear who Swims

cpcahil@virtech.UUCP (Conor P. Cahill) (09/09/89)

In article <614@jvncf.UUCP>, saroff@jvncf.UUCP (Steve Saroff lac00001) writes:
> 1) Can you tell me why when I try to read in a file with the
> ":r" command, it barfs for long path names?

It never happens to me.

> 2) Is there any quick and dirty way of inserting a character(s) say
> at the front of lines (e.g. quick commenting out of 20 lines of code)

	:start_line_no,end_line_no s/^/# /

which places a "# " at the beginning of each line between, and including, 
start_line_no and end_line_no

Usually I go to the first line and mark it with an a by typing "ma"
then I go  to the last line and type the following:

	:'a,. s/^/# /

-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+

dberg@cod.NOSC.MIL (David I. Berg) (09/10/89)

In article <614@jvncf.UUCP>, saroff@jvncf.UUCP (Steve Saroff lac00001) writes:
> 2) Is there any quick and dirty way of inserting a character(s) say
> at the front of lines (e.g. quick commenting out of 20 lines of code)

Note that the ^ character is a symbolic variable whose value is the null
position in front of the first character of each line (just like $ is the
symbolic variable whose value is the null position at the end of each line).  
If you want to insert a # in front of every line in the file:

:%s/^/#/

If you want to comment out the next twenty lines from and including the
current line:

:.,+20s/^/#/

etc through all the variations on this theme.

-- 
David I. Berg (dberg@nosc.mil)
GENISYS Information Systems, Inc., 4250 Pacific Hwy #118, San Diego, CA 92110
MILNET: dberg@nosc.mil
UUCP:   {akgua decvax dcdwest ucbvax}!sdcsvax!noscvax!dberg

bph@buengc.BU.EDU (Blair P. Houghton) (09/10/89)

In article <614@jvncf.UUCP> saroff@jvncf.csc.org.UUCP (Steve Saroff lac00001) writes:
>I have two questions.
>
>1) Can you tell me why when I try to read in a file with the
>":r" command, it barfs for long path names?

Most vi's do globbing (filename expansion) internally, rather than
asking the system to do it.  This causes many problems, because the
do-it-yourselfers wrote a lousy globber.  I always try to use wildcards
and tildes in filenames, and get "too many filenames" as a response.
Apparently, though I've never seen it with mine, yours has a too-short
buffer for the filename.

I've always wanted to get ahold of a real vi source and fix it so
that the :r and :w commands do a system call that uses sh to do
its globbing.  Then again, for all I know it's actually passing the
ex-commands (commands that start with a colon) unglobbed to ex, and
it's ex that I need to fix.

>2) Is there any quick and dirty way of inserting a character(s) say
>at the front of lines (e.g. quick commenting out of 20 lines of code)

Quick _and_ dirty?  Well, either

I#<esc><cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.<cr>.

or

:wq<cr><ctrl-D>(pad, pad, pad, pad, pad, pad, pad, pad, thwap! flip,
page, page, page)<RTFM>.

				--Blair
				  "...and comp.editors..."

bph@buengc.BU.EDU (Blair P. Houghton) (09/10/89)

In article <4092@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>I've always wanted to get ahold of a real vi source and fix it so
>that the :r and :w commands do a system call that uses sh to do
>its globbing.  Then again, for all I know it's actually passing the
>ex-commands (commands that start with a colon) unglobbed to ex, and
>it's ex that I need to fix.

No, it's ME I need to fix.

for the past forever, I've been having that problem.  Now I am told
that vi does indeed pass the globbing onto csh, and that it's only
because I am to bonehead-f****ing lazy to put

    if ( $?prompt ) then
	set prompt="subwhat? "
    else
	unset prompt
    endif

in my .cshrc that I am having this problem, because csh is returning
my subshell-prompt (my csh prompt is "what? ") to vi, which then
thinks I want it as a file, in addition to the file csh probably
properly globbed...

Excuse me.

(Shuffle, pad, pad, pad, bend, wrench-CLANG! "ouch" wrench-CLANG! "ouch"
wrench-CLANG! "ouch"...)  [Repeat until either head or wastebasket
is dented beyond recognition.]

PLUS, I use the $?prompt feature on another machine, on which I have
done plenty of editing, but was so ingrained by my ignorance and sloth
("drat, there's that prompt coming back in the output from a
pipe-command again, one of these days I gotta put that $?prompt
condition in my .cshrc," I have said to myself almost daily...) on this
one that I never noticed that globbing would work.

				--Blair
				  "...an elephant is warm and mushy..."

P.S. AND I managed to delete the message from the kind person
who told me this was the likely cause, so all I can say is
"thank you, eirik@labs.labs.tek.com, whoever you are"...

bph@buengc.BU.EDU (Blair P. Houghton) (09/10/89)

In article <4107@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>In article <4092@buengc.BU.EDU> bph@buengc.bu.edu (Blair P. Houghton) writes:
>>I've always wanted to get ahold of a real vi source and fix it so
>				  "...an elephant is warm and mushy..."
>
>P.S. AND I managed to delete the message from the kind person
>who told me this was the likely cause, so all I can say is
>"thank you, eirik@labs.labs.tek.com, whoever you are"...

Eirik Fuller.  Tektronix.

Smart and well-experienced person.   I'm glad to call him "friend".

				--Blair
				  "Call me Ishmael.  That's
				   whaleblubber for 'lunchmeat.'
				   It's me through and through,
				   today."

rbj@dsys.ncsl.nist.gov (Root Boy Jim) (09/19/89)

? From: "Blair P. Houghton" <bph@buengc.bu.edu>

? No, it's ME I need to fix.

? for the past forever, I've been having that problem.  Now I am told
? that vi does indeed pass the globbing onto csh, and that it's only
? because I am to bonehead-f****ing lazy to put

?     if ( $?prompt ) then
? 	set prompt="subwhat? "
?     else
? 	unset prompt
?     endif

The else clause is unnecessary. Also, you might as well simply exit
your .cshrc at this point, as you most likely don't want any aliases
or variables set. The general form of .cshrc should be:

	<stuff you always want to do>
	if ($?prompt == 0) exit
	<interactive stuff>

	Root Boy Jim and
	the GNU Bohemians

bph@buengc.BU.EDU (Blair P. Houghton) (09/20/89)

In article <20884@adm.BRL.MIL> rbj@dsys.ncsl.nist.gov (Root Boy Jim) writes:
>? From: "Blair P. Houghton" <bph@buengc.bu.edu>
>
>? No, it's ME I need to fix.
>
>?     if ( $?prompt ) then
>? 	set prompt="subwhat? "
>?     else
>? 	unset prompt
>?     endif
>
>The else clause is unnecessary.

The else-clause shown is degenerate for the purposes of the
example.  The one I use has more than an unset in it.

>Also, you might as well simply exit

I especially dislike using 'exit' as a conditional structure.
I reserve it for error conditions.

>your .cshrc at this point, as you most likely don't want any aliases
>or variables set. The general form of .cshrc should be:
>
>	<stuff you always want to do>
>	if ($?prompt == 0) exit
>	<interactive stuff>

But, I shell-out of vi(1andonly) all the time.

If for instance I'm editing some C and want to go take a fast look at
a header file, I'll just

	:!m $INC/stdio.h

Which requires that I have the aliasing rerun, and set
INC to /usr/include.  Further, I don't even set the variable INC unless I'm
inside vi(1forall) and shelling out noninteractively.  Any other time the
extra bit of typing won't bother me.

				--Blair
				  "Still running fine since
				   the tune-up."

dhesi@sun505.UUCP (Rahul Dhesi) (09/22/89)

In article <20884@adm.BRL.MIL> rbj@dsys.ncsl.nist.gov (Root Boy Jim) writes:
>	<stuff you always want to do>
>	if ($?prompt == 0) exit
>	<interactive stuff>

I had csh scripts like this; they broke after an OS upgrade from 4.3BSD
to Mt Xinu's More/BSD.  I think the longer form

     if ($?prompt) then
        ...
     endif

will be more portable.

My guess is that when it sees "exit", csh can't decide whether to exit
just the script being source'd or to exit itself entirely.
--
Rahul Dhesi <dhesi%cirrusl@oliveb.ATC.olivetti.com>
UUCP:  oliveb!cirrusl!dhesi