开发者

Try-catch in Vimscript

开发者 https://www.devze.com 2023-03-02 16:26 出处:网络
I am trying to catch an error (E490) in Vim like this: :try | foldopen! | catch | | endtry Still, when executing this, Vim shows the error:

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

精彩评论

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