7

Looking for lambda in the doc, I've found out (to my surprise) that they do exist in vimscript, and they use the syntax {args -> expr1}.

But I've also discovered that there's Vim9, the doc of which is at :help Vim9, which offers a different syntax for lambdas: (args) -> expr1.

However, if I try entering :echo ((x) => x*2)(3) I get E110.

After all, I'm using Vim 8.2. But then why do I have Vim9 doc?

2 Answers 2

7

Because Vim9 has not been formally released yet, but the features are ready to try out in the latest Vim8 releases.

If you see it in the help, then you can use it two ways:

The Vim9 script syntax and semantics are used in:
- a function defined with the `:def` command
- a script file where the first command is `vim9script`

That doesn't include an :echo statement at the command line, like what you tried.

3

To maintain backward compatibility, the commands you enter at the command-line prompt (:) are interpreted as pre-Vim9 legacy commands. You can prefix the command with 'vim9cmd' to interpret it as a Vim9 command. For the example command that you quoted above, you can use the following:

vim9cmd echo ((x) => x * 2)(3)

For more information, refer to:

https://vimhelp.org/vim9.txt.html#%3Avim9cmd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.