如何在`vim`和`nvim`中调试`处理函数时`错误?

cpr*_*prn 4 debugging vim neovim

TL; DR

当我有兴趣修复实际问题而不只是删除坏插件时,如何找到确切的位置vimnvim错误开始(哪个文件?)?strace找到错误来源还有什么比猜测更好的东西?

问题

我经常在我的vimnvim配置中添加一个插件,并最终在钩子上获得错误(缓冲区打开,关闭,写入):

"test.py" [New] 0L, 0C written
Error detected while processing function 343[12]..272:
line    8:
E716: Key not present in Dictionary: _exec
E116: Invalid arguments for function get(a:args, 'exec', a:1['_exec'])
E15: Invalid expression: get(a:args, 'exec', a:1['_exec'])
Run Code Online (Sandbox Code Playgroud)

问题是,我不知道它们来自哪里,只得到一些未知文件的行号,我知道它不是我的vim/ nvimconfig文件.

Luc*_*tte 7

在某个地方,你有一个插件定义了一个字典anonymous-functions(检查与此标签相关的帮助).

对于好奇的人来说,就是这样做的:

let d = {}
function! d.whatever() abort
   throw "blah"
endfunction
Run Code Online (Sandbox Code Playgroud)

执行此功能时,您将收到当前正在观察的错误.这就是为什么我停止这种方式更喜欢:

let d = {}
function s:whatever() abort
   throw "blah"
endfunction
let d.whatever = function('s:whatever') " a workaround is required for older versions of vim
" At least this way I'll get a `<SNR>42_whatever` in the exception throwpoint, and thus a scriptname.
Run Code Online (Sandbox Code Playgroud)

这就是原因.现在,回到你的问题,AFAIK,你唯一能够知道的就是被调用的两个函数:

  • 在第12行:function {343},已经打过电话了
  • :function {272} 其中包含第8行的错误.

感谢这两个命令(可能是前缀:verbose,我不记得确切),您将获得这两个函数的源代码,您应该可以使用它们来插入插件以了解它的出现位置.