Friday, October 28, 2022

Re: Share variables between Two vim9 def functions

> Vim9script introduces the fact of having to use a global to pass values
> ​​between a P function, producing its values, used for example in an
> autocommand and a second C function consuming its data / values ​​which
> would be called on a key mapping for example. The fact is that going
> through globals is not very elegant and forced to create a new global named
> different in each new case explained above. So I was looking for another
> way.

With Vim9 script the recommended way is to put the variable in one
script where it is exported, and then import it whereever you want to
use it. That way you have control over where the value is changed, make
it a constant, etc. See help for "vim9-scopes" and ":import".

--
Westheimer's Discovery:
A couple of months in the laboratory can
frequently save a couple of hours in the library.

/// Bram Moolenaar -- Bram@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 ///

--
--
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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20221028214359.A00A91C0739%40moolenaar.net.

No comments:

Post a Comment