How to know from which line a script is called?

陌路散爱 提交于 2019-12-11 19:58:38

问题


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.



来源:https://stackoverflow.com/questions/25462500/how-to-know-from-which-line-a-script-is-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!