Reply to message «Re: Performing mapped command on the command line», sent 15:21:45 04 February 2011, Friday by Marco:
> > > I want to remap <C-R> with
> > > my own function and at the end of my own function I want to call the
> > > function of the former mapping.
> >
> > I used to either create a temporary mapping:
> >
> > [...]
>
> Sorry, but that's too much unknown code for me. I'm not an expert in vim
> programming.
There is nothing special here: first is mapping command constructor, second
obtains mapping dictionary (Note `hasdictmap' variable, it checks for vim
version. If you know that its value will be true, you could throw away 90% of
this function code). It is trivial, you just have to know special arguments of
`map' command, all are referenced in :h maparg() (>=vim-7.3.32) and the fact
that `<SID>' expands to `<SNR>{N}_' where N is script number: it is described
in
:h <SID> which is also referenced in :h maparg(). You don't need this code for
this particular task, but it is a generic way to call old mapping after
redefining {rhs}.
Original message:
> On 2011-02-04 ZyX <[email protected]> wrote:
> > > I tried something like:
> > >
> > > vim.eval"<Plug>IMAP_JumpBack"
> > >
> > > But it's not working. How to call this from within lua?
> >
> > vim.eval will evaluate expression. <Plug>IMAP_JumpBack is not an
> > expression. Expr definition can be found in :h expr.
>
> Okay, thanks.
>
> > If it was python, I
> > would have used vim.command('execute "normal \\<Plug>IMAP_JumpBack"').
>
> Bingo! That's the solution. Works in lua, too.
>
> > > What elst can I rely on? Only the <C-R> mapping?
> >
> > You should rely on documented API. You should not rely on <C-r> mapping
> > because you are going to remap it, but IMAP_JumpBack is documented.
>
> That's what I use.
>
> > > I want to remap <C-R> with
> > > my own function and at the end of my own function I want to call the
> > > function of the former mapping.
> >
> > I used to either create a temporary mapping:
> >
> > [...]
>
> Sorry, but that's too much unknown code for me. I'm not an expert in vim
> programming.
>
> > This is to be used inside an expression mappings when you cannot know
> > what is the {rhs} and where it is defined. You probably don't nee such
> > monster
> >
> > here. You may also do the following:
> > imap <C-r> <Plug>MappingToYourFunction<Plug>IMAP_JumpBack
>
> Looks much better. I'll try.
>
> > this should also work:
> > function ExecuteJumpBack()
> >
> > return "\<Plug>IMAP_JumpBack"
> >
> > endfunction
> > imap <expr> {lhs} ExecuteJumpBack()
> >
> > The following can also work, but I did not test it:
> > imap {lhs} <C-r>=ExecuteJumpBack()<CR>
> >
> > Other possibilities:
> > function ExecuteJumpBack()
> >
> > execute "normal i\<Plug>IMAP_JumpBack"
> >
> > endfunction
> > function ExecuteJumpBack()
> >
> > " Assuming that after function execution it will be still in
> > insert
> >
> > mode call feedkeys("\<Plug>IMAP_JumpBack")
> >
> > endfunction
>
> Thanks for the suggestions. I'll play with them.
>
>
> Regards
> Marco
signature.asc
Description: This is a digitally signed message part.
