Reply to message «Re: Performing mapped command on the command line», sent 01:10:05 04 February 2011, Friday by Marco:
> It's just for testing. It also works from within a vim script. The next
> step is to put it in a lua script. But I'm not successfull. 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. If it was python, I would have used
vim.command('execute "normal \\<Plug>IMAP_JumpBack"').
> 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.
> 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:
function s:ExecuteOldMap(exmap)
let exmap=a:exmap
execute "i".((exmap.noremap)?("nore"): (""))."map <special> ".
\"<buffer> ".
\((exmap.silent)? ("<silent> "):("")).
\((exmap.expr)? ("<expr> "): ("")).
\"<Plug>Translit3TempMap ".
\substitute(exmap.rhs, '<SID>', '<SNR>'.exmap.sid.'_',
\ 'g')
return "\<C-\>\<C-o>:call feedkeys(\"\\<Plug>Translit3TempMap\")\n"
endfunction
let s:exmaps={}
function s:SaveOldMap(char)
let hasdictmap=(v:version==703 && has("patch32")) || v:version>703
if hasdictmap
let exmap=maparg(a:char, "i", 0, 1)
else
let exmap=maparg(a:char, "i")
endif
if !empty(exmap)
if hasdictmap
let s:exmaps[a:char]=exmap
else
redir => eximapredir
silent! execute "imap ".char
redir END
let eximapredir=eximapredir[1:-2]
let eximaptype=eximapredir[(-len(exmap)-2)][0]
let noremap=0
if eximaptype==#'*'
let mapcmd=1
endif
let s:exmaps[a:char]={
\ "lhs": a:char,
\ "rhs": exmap,
\ "silent": 0,
\"noremap": noremap,
\ "expr": 0,
\ "buffer": 2,
\ "mode": "i",
\ "sid": 0,
\}
endif
endif
endfunction
call SaveOldMap('{lhs}')
inoremap <expr> {lhs} <SID>ExecuteOldMap(s:exmaps['{lhs}'])
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
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
Original message:
> On 2011-02-03 ZyX <[email protected]> wrote:
> > > How can I perform the command from the command line? A
> >
> > Try
> >
> > execute "normal i\<Plug>IMAP_JumpBack"
>
> Thanks that works.
>
> > . And what for do you need to invoke it from command line?
>
> It's just for testing. It also works from within a vim script. The next
> step is to put it in a lua script. But I'm not successfull. I tried
> something like:
>
> vim.eval"<Plug>IMAP_JumpBack"
>
> But it's not working. How to call this from within lua?
>
> > By the way,
> > IMAP_Jumpfunc is not in a documented API, so you should not rely on this
> > mapping being the same for newer version.
>
> What elst can I rely on? Only the <C-R> mapping? 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 sometimes change internal
> > implementation of my plugin features without notice, but try to keep
> > public API backwards compatible or at least notify about changes. I
> > believe this is common in developers world, especially for (relatively)
> > small vim plugins.
>
> What is a better way, if I want my own mapping but still need the
> functionality of the former mapping?
>
>
> Regards
> Marco
signature.asc
Description: This is a digitally signed message part.
