gpt4 book ai didi

Vimscript : what's the point of 'abort' in a function definition?

转载 作者:行者123 更新时间:2023-12-03 20:39:27 25 4
gpt4 key购买 nike

在 vimscript 中,function定义可以采用 abort争论。引用文档,

When the [abort] argument is added, the function will
abort as soon as an error is detected

这让我认真地质疑函数在遇到错误时通常会做什么。盲目地跌入黑暗?

什么 abort其实呢?它是否会破坏所有 try...endtry块?你什么时候想使用它,什么时候你想避免它?

最佳答案

正如 glts 提到的,所有复杂的细节都记录在 :help except-compat ,答案基本上归结为向后兼容性和 Vimscript 固有的灵活性。

从录制的宏到映射到自定义函数,这是一个自然的过程。考虑到这一点,当函数中的命令导致错误(例如 %s/foo/bar/ 不匹配且缺少 e 标志)时,处理应该继续。

另一方面,当您编写“工业级”映射时,您几乎总是使用 try..catch无论如何(为了避免任何多行错误 Error detected while processing function: ... ,而是向用户显示一个很好的错误消息)。

所以在实践中,大多数发布的插件不使用 abort ,但是 try..catch ,对于快速的、即兴的东西,无论如何你通常不太关心错误处理。

关于Vimscript : what's the point of 'abort' in a function definition?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13425648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com