-->

How to know from which line a script is called?

2019-09-18 06:17发布

问题:

I would like to know from which line a script is called.

Code:

...
line 500
line 501  an <silent> 98.80.00 &Files.Test\ single\     :call Func('%')<CR>
line 502
etc

desired output: 501

Is it possible?

回答1:

Apart from the question about "do you really need this?", here is a trick:

"foo
"bar
let a = 5
let a = 5
let a = 5
call  Foo(search('very special string'))
let a = 5
let a = 5
fun! Foo(callerLineNumber)
    echo a:callerLineNumber
endf

this will print the line number of line call Foo(search('"very special string"'))

well you have to make a "really special string" in search pattern.