Salman Halim wrote:
> It's my understanding that Vim 9 functions will get compiled and will be
> faster than legacy functions, so I'm changing some stuff I've written, but
> I have some questions:
>
> 1. How can I use a Vim 9 function in a mapping? Something like: nmap abc
> <CMD>call Vim9Func()<cr>
Just like before.
> 2. Can I call a Vim 9 function defined in another script from a legacy Vim
> script? How?
Just call it. Keep in mind that in Vim9 script functions are
script-local by default. You can either prefix "g:" to make them global
or use some way to call the script-local function, e.g. by using
:import.
> 3. Can a Vim 9 function be defined inside another function? I want to call
> an outer function that defines some variables and then returns a function
> that will have access to those variables, as in a closure or a partial
> function (where the first few arguments to the function are preset).
This mostly works as you expect.
> Examples of each would be great, if possible, please. I did look through
> the documentation, but wasn't able to work these out for myself.
vim9script
def Test()
var text = 'asdf'
def Inner(): string
return text .. '1234'
enddef
echo Inner()
enddef
Test()
--
What do you get when you cross a joke with a rehtorical question?
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///