Vim脚本有办法停止任何错误吗?

一个简单的例子:

function! Foo()
    echom 'Starting Foo'
    let x = Bar(123)  " Function does not exist so E117 occurs.
    echom 'Nonetheless, this executes.'
endfunction

如果发生任何错误,Vim 是否具有中止函数或脚本的机制——换句话说,与bash.

set -o errexit

澄清一下,我了解如何在try-catch. 我正在寻找一种通用机制来让 Vim 脚本的行为类似于 Python、Ruby、Perl 等语言,在这些语言中,未处理的错误会导致执行停止。

回答

TL; 博士

始终标记函数 abort


您的问题最近在 vi.SE 上有重复:https ://vi.stackexchange.com/questions/29038/how-do-i-make-a-function-stop-when-an-error-occurs/29039#29039
或者,关于同一主题:https : //vi.stackexchange.com/questions/15905/when-should-a-function-not-be-defined-with-abort

在 SO 上,还有一些关于abort以下内容的解释:Vimscript:函数定义中的“中止”有什么意义?


以上是Vim脚本有办法停止任何错误吗?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>