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 -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_use/202106031956.153JukdS2930913%40masaka.moolenaar.net.

Reply via email to