maps can't access class instance variable 'this'

13 views
Skip to first unread message

Christian J. Robinson

unread,
Jun 11, 2023, 1:48:41 PM6/11/23
to bu...@vim.org, vim_dev
As the subject says, if I create a class that ultimately defines a mapping when a new instance is created, unfortunately the mapping can't access the "this" variable of the instance.

Is there a way to do this I'm not seeing in the documentation?

--
Christian J. Robinson <hep...@gmail.com>

Bram Moolenaar

unread,
Jun 12, 2023, 4:18:18 PM6/12/23
to vim...@googlegroups.com, Christian J. Robinson

> As the subject says, if I create a class that ultimately defines a mapping
> when a new instance is created, unfortunately the mapping can't access the
> "this" variable of the instance.
>
> Is there a way to do this I'm not seeing in the documentation?

You probably need to use a closure. That is the only way you can bind a
variable and pass the reference around. You can find hints around
":help E1271".

Keep in mind that mappings work in the global namespace. To access
something local to the script you can use <SID> or <ScriptCmd>.
You may first give <ScriptCmd> a try.

--
hundred-and-one symptoms of being an internet addict:
158. You get a tuner card so you can watch TV while surfing.

/// 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 ///

Christian J. Robinson

unread,
Jun 12, 2023, 7:04:34 PM6/12/23
to Bram Moolenaar, vim...@googlegroups.com
Neither worked for me, so I guess what I'm trying to do is a non-starter.
Reply all
Reply to author
Forward
0 new messages