开发者

Try-catch in Vimscript

I am trying to catch an error (E490) in Vim like this:

:try | foldopen! | catch | | endtry

Still, when executing this, Vim shows the error:

Error detected while processing :
E490: No fold fo开发者_如何学Gound

I would like to open all folds if any are present.

Any ideas?


Looks like a bug: your version shows an error,

:execute 'try | foldopen! | catch | | endtry'

acts like

:echo 'try | foldopen! | catch | | endtry'

without folds.

Try the following workaround:

:execute "try\n    foldopen!\ncatch\nendtry'

By the way, there is a better way if you want to ignore all errors:

:silent! foldopen!

Note that it won't purge messages from redirection if it is present, while try...catch will.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜