fyl@ssc.UUCP (Phil Hughes) (11/03/90)
A friend just asked how to include the name of the current file
in vi. In other words, he wants the current file pathname inserted
into the text for reference purposes. I couldn't think of how to do it.
I wrote the shell script below as a nasty hack to solve the problem but
it seems there must be a vi'ish way to do it.
----------nasty hack follows--------------
: nvi
# create new file and put filename into it
# call with:
# nvi filename
# make sure nvi was called with one argument
if [ $# -ne 1 ] ; then
echo "usage: nvi filename"
exit 1
fi
# make sure specified file doesn't exist
if [ -f "$1" ] ; then
echo "$0: $1 already exists"
exit 1
fi
# prepend path to filename if it doesn't start with a /
if [ `expr $1 : "\/"` -eq 1 ] ; then
pn=$1
else
pn=`pwd`/$1
fi
# create the file with a filename line in it
echo File: $pn >$pn
# invoke vi
vi $pn
--
Phil Hughes, SSC, Inc. P.O. Box 55549, Seattle, WA 98155 (206)FOR-UNIX
uunet!pilchuck!ssc!fyl or attmail!ssc!fyl (206)527-3385Dan_Bloch@TRANSARC.COM (11/04/90)
fyl@ssc.UUCP (Phil Hughes) writes: > A friend just asked how to include the name of the current file > in vi. In other words, he wants the current file pathname inserted > into the text for reference purposes. To insert the filename as it was given to vi: :r !echo % To insert the current pathname followed by this: :r !echo $cwd/% Dan Bloch dan@transarc.com
dattier@ddsw1.MCS.COM (David W. Tamkin) (11/04/90)
fyl@ssc.UUCP (Phil Hughes) wrote in <484@ssc.UUCP>: | A friend just asked how to include the name of the current file | in vi. In other words, he wants the current file pathname inserted | into the text for reference purposes. I couldn't think of how to do it. | I wrote the shell script below as a nasty hack to solve the problem but | it seems there must be a vi'ish way to do it. :r !echo % In shell escapes, vi replaces unquoted percent signs with the current file name. David Tamkin Box 7002 Des Plaines IL 60018-7002 708 518 6769 312 693 0591 MCI Mail: 426-1818 GEnie: D.W.TAMKIN CIS: 73720,1570 dattier@ddsw1.mcs.com
dattier@ddsw1.MCS.COM (David W. Tamkin) (11/05/90)
Dan_Bloch@TRANSARC.COM wrote in <sbAjPar0BwwZ0TUlMy@transarc.com>: | To insert the filename as it was given to vi: | | :r !echo % | | To insert the current pathname followed by this: | | :r !echo $cwd/% The second suggestion is rather csh-specific. In sh or ksh, :r !echo $PWD/% is the equivalent, but the current directory will get named twice if vi was given the full pathname. [That might happen with Dan's suggestion as well; I know nothing about csh, but I get the feeling it would.] $cwd|$PWD will genrally match the directory % is in if % is not a full path. If you have a command available that gives full paths for files (let's call it "path" for the example), then :r !path % should work regardless of which shell you're using. David Tamkin Box 7002 Des Plaines IL 60018-7002 708 518 6769 312 693 0591 MCI Mail: 426-1818 GEnie: D.W.TAMKIN CIS: 73720,1570 dattier@ddsw1.mcs.com