Thursday, July 7, 2011

Re: Is there any __FILE__, __FUNCTION__, __LINE__ equivalent for vim script?

Reply to message «Re: Is there any __FILE__, __FUNCTION__, __LINE__ equivalent
for vim script?»,
sent 07:17:03 08 July 2011, Friday
by Ben Fritz:

> <sfile> and <slnum> will give you __FILE__ and __LINE__. I don't think
> there's a __FUNCTION__ but I could be wrong.
<sfile> can be used in place of both a __FILE__ and a __FUNCTION__, depending
from where it is called. If called outside of a function, it will give you a
function stack.

By the way, where did you get <slnum>? It works, but :helpg slnum shows nothing.

Original message:
> On Jul 7, 8:39 pm, pansz <pan.shi...@gmail.com> wrote:
> > For debug reason we often need to print the current script name,
> > function name and line number.
> >
> > suppose vim script is a program, is it possible to get the current
> > script name and the current execution line in vim script? is there any
> > functions of macros to get them?
>
> <sfile> and <slnum> will give you __FILE__ and __LINE__. I don't think
> there's a __FUNCTION__ but I could be wrong.
>
> IIUC you use them inside expand(), like:
>
> echomsg expand("<sfile>") "on line" expand("<slnum>")

No comments: