Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 found

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

Any ideas?

like image 249
Nickolay Kolev Avatar asked May 01 '11 17:05

Nickolay Kolev


1 Answers

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.

like image 171
ZyX Avatar answered Nov 04 '22 20:11

ZyX