Accessing mapping from rhs

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing mapping from rhs

Lifepillar
Is it possible to access the lhs of a mapping from its rhs?
For example, given:

imap <expr> <cr> MyFunction()

is there a way for MyFunction() to know that it was called by <cr>?

Thanks,
Life.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing mapping from rhs

Christian Brabandt

On Do, 30 Aug 2018, Lifepillar wrote:

> Is it possible to access the lhs of a mapping from its rhs?
> For example, given:
>
> imap <expr> <cr> MyFunction()
>
> is there a way for MyFunction() to know that it was called by <cr>?

Not that I know of and I have whished for that before.

Best,
Christian
--
Wenn ein Kolonialwarenhändler in seinem kleinen Laden so viele
Dummheiten und Fehler machte wie die Staatsmänner und Generäle in
ihren großen Ländern, wäre er in spätestens vier Wochen bankrott.
                -- Erich Kästner

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing mapping from rhs

John Passaro
Could you implement the function and accompanying mapping as follows?

imap <expr> <cr> MyFunction("cr")
imap <expr> <Leader>n MyFunction("Leader-n")

Sorry if this is obvious, if it is impractical for some reason I'm curious why.

John Passaro
(917) 678-8293

On Thu, Aug 30, 2018 at 1:18 PM, Christian Brabandt <[hidden email]> wrote:

On Do, 30 Aug 2018, Lifepillar wrote:

> Is it possible to access the lhs of a mapping from its rhs?
> For example, given:
>
> imap <expr> <cr> MyFunction()
>
> is there a way for MyFunction() to know that it was called by <cr>?

Not that I know of and I have whished for that before.

Best,
Christian
--
Wenn ein Kolonialwarenhändler in seinem kleinen Laden so viele
Dummheiten und Fehler machte wie die Staatsmänner und Generäle in
ihren großen Ländern, wäre er in spätestens vier Wochen bankrott.
                -- Erich Kästner

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing mapping from rhs

Christian Brabandt

On Do, 30 Aug 2018, John Passaro wrote:

> Could you implement the function and accompanying mapping as follows?
>
> imap <expr> <cr> MyFunction("cr")
> imap <expr> <Leader>n MyFunction("Leader-n")

This is the typical workaround. The idea was to be able to know in the
function which mapping triggered the call to it, without having special
arguments (which look like they contain redundant information).

Best,
Christian
--
Auch wenn es Dich empört: Das Unerlaubte Vergnügen macht Spaß.
                -- Ovid (43 v.Chr.-18 n.Chr)

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Accessing mapping from rhs

Lifepillar
On 30/08/2018 20:37, Christian Brabandt wrote:

>
> On Do, 30 Aug 2018, John Passaro wrote:
>
>> Could you implement the function and accompanying mapping as follows?
>>
>> imap <expr> <cr> MyFunction("cr")
>> imap <expr> <Leader>n MyFunction("Leader-n")
>
> This is the typical workaround. The idea was to be able to know in the
> function which mapping triggered the call to it, without having special
> arguments (which look like they contain redundant information).

Christian, John,
thanks for your replies. Yes, that's what I am currently doing in my
plugin, and it's a very flexible solution, since the argument of
MyFunction does not have to be equal to the lhs.

I was just curious whether one could replace it with

     imap <cr> <plug>(MyPlug)

where <plug>(MyPlug) maps to some function. In this case, you cannot
pass arguments, so I was wondering whether one could access the lhs of
the mapping through the plug (presumably, via some special variable).
I couldn't find any way, but I wanted to make sure I wasn't missing
anything from the documentation.

To be clear, this is not a feature request: the "typical workaround", as
I've said, is just fine.

Thanks again,
Life.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.