[net.unix] Can you access the current file name in a vi macro?

diamant@wanginst.UUCP (Ira Diamant) (01/25/85)

	Does anyone know if there is a way to access the name of the current 
file in vi?  I want to build a small template generator using macros, but
I have not been able to find this information in the documentation.

				Thanks in advance

west@sdcsla.UUCP (Larry West) (01/25/85)

In article <153@wanginst.UUCP> diamant@wanginst.UUCP (Ira Diamant) writes:
>
>	Does anyone know if there is a way to access the name of the current 
>file in vi?  I want to build a small template generator using macros, but
>I have not been able to find this information in the documentation.
>
>				Thanks in advance

Well, sort of.   The character "%", used in shell-escapes (":!" or
"!<motion>" [e.g., "!!" for one line]) is expanded to the current
filename.   Likewise, "#" is expanded to the alternate filename,
if any.   For exmaple, try this command:
	:!ls -l %

So you could put that command into a mapping (and probably a macro
but not an abbreviation) by doing something like:
	:map V :!ls -l %^V^M

This will not work on older versions of VI for various reasons.

Hope this confuses you at least a little.
-- 

--|  Larry West, UC San Diego, Institute for Cognitive Science
--|  UUCP:	{decvax!ucbvax,ihnp4}!sdcsvax!sdcsla!west
--|  ARPA:	west@NPRDC	{ NOT: <sdcsla!west@NPRDC> }

foss@ihuxo.UUCP (John Doe) (01/31/85)

	Yes,
		Use the % anywhere you would use the 
		name of the file in the current buffer.

	Ex.

		:!ls %
		
		would expand to

		ls <filename>

gbergman@ucbtopaz.CC.Berkeley.ARPA (01/31/85)

In article <768@sdcsla.UUCP> west@sdcsla.UUCP (Larry West) writes:

>In article <153@wanginst.UUCP> diamant@wanginst.UUCP (Ira Diamant) writes:
>>
>>	Does anyone know if there is a way to access the name of the current 
>>file in vi?  I want to build a small template generator using macros, but
>>I have not been able to find this information in the documentation.

     West points out that the character % in command escapes is expanded
to the current filename.
     If one only wants to _s_e_e the current filename, the command
^G  or  :file<CR>  will show that.  But if one wants to get it into the
file (other than by copying by hand from the bottom line the result of
one of the above commands) then an application of the feature West
mentioned is needed.  The command
	:[address]r !echo %
seems the best way.  It can be used in editor scripts as well as
mappings.  The disadvantage is that shell escapes are slow.
And a general disadvantage of using % is that it shows the current
file name *as one originally called it*, not in any uniform format --
It will be shown relative to the directory one was in when one
entered vi, unless one used an absolute address or called it relative
to one's own or another's home directory, in which case it will have
an absolute address.
			George Bergman
			Math, UC Berkeley 94720 USA
			...!ucbvax!gbergman%cartan.Berkeley