Can you access the current file name in a vi macro?

gbergman at ucbtopaz.CC.Berkeley.ARPA gbergman at ucbtopaz.CC.Berkeley.ARPA
Fri Feb 1 04:57:41 AEST 1985


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

>In article <153 at wanginst.UUCP> diamant at 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



More information about the Comp.unix mailing list