In vimscript, function
definitions can take an abort
argument. To quote the docs,
When the [abort] argument is added, the function will abort as soon as an error is detected
This leads me to seriously question what exactly functions normally do when they encounter errors. Stumble blindly forth into the darkness?
What does abort
actually do? Does it break all of the try...endtry
blocks? When do you want to use it, and when do you want to avoid it?
l: local to a function. g: global. :help internal-variables. Follow this answer to receive notifications.
Calling A Function Vim has a :call command to call a function. The call command does not output the return value. Let's call it with echo . To clear any confusion, you have just used two different call commands: the :call command-line command and the call() function.
Plain old :echo will print output, but it will often disappear by the time your script is done. Using :echom will save the output and let you run :messages to view it later.
As glts mentioned, all the complex details are documented at :help except-compat
, and the answer basically boils down to backwards compatibility and the inherent flexibility of Vimscript.
There's a natural progression from recorded macros to mappings to custom functions. With that in mind, it may make sense that when a command in a function causes an error (e.g. a %s/foo/bar/
that is not matching and missing the e
flag), processing should continue.
On the other hand, when you write "industrial-grade" mappings, you'll almost always use a try..catch
block inside your function call hierarchy, anyway (to avoid any multiline-errors Error detected while processing function: ...
, and instead show a nice error message to the user).
So in practice, most published plugins do not use abort
, but try..catch
, and for quick, off-the-cuff stuff, you typically don't care too much about error handling, anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With