vim: 防止 :exe 在出错后退出

vim: Prevent :exe from quitting after error

我有一个单行错误检查 vim 命令,如下所示。它不是问题的直接部分,而是作为一个例子,所以请随意忽略它:

:'<,'>g/foo{.*}/exe "norm! mxf{lvt}y/\(foo{\)\@!\<C-R>\"\<enter>yy'xP"

解释如下:

这基本上是一个错误检查命令,用于查看每次一个术语被 foo{ 包裹时,总是 被 foo 包裹。但是,exe/(正向搜索)没有找到任何东西的第一种情况下退出。我不希望发生这种情况。

如何使 exe:g 即使在 exe 命令中出现错误也能继续? 我试过 :silent,但这并不能保存它。

我宁愿将其保留为一行,但函数是我可以接受的第二个选项。

:silent 是不够的。您需要使用 :silent!。来自 :help :silent(强调我的):

When [!] is added, error messages will also be skipped, and commands and mappings will not be aborted when an error is detected.