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

Larry West west at sdcsla.UUCP
Fri Jan 25 20:25:32 AEST 1985


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.
>
>				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 at NPRDC	{ NOT: <sdcsla!west at NPRDC> }



More information about the Comp.unix mailing list