Reply to message «Re: [BUG] feedkeys() does not work inside an <expr> mapping», sent 16:05:51 08 March 2011, Tuesday by Christian Brabandt:
> I think, expr-mappings don't see the typeahead until after the mapping
> finished. If you want to use feedkeys() inside an expression mapping, you
> need to return the feedkeys call, e.g (untested):
> return ':call feedkeys("i".g:n."\e")'."\n"
I don't want to see typeahead (the fact that it is not seen is documented). I
just want to feed back characters that were obtained by getchar() but actually
were not consumed. Now I append to the {rhs} a call to a function that uses
global variable to determine whether there are actually some additional keys as
a workaround (feedkeys() is much cleaner and does not depend on presence of
`nore' in a mapping command). I cannot use ``return ":call feedkeys(...)"''
because I do not know mode in which I will end up.
Original message:
> On Tue, March 8, 2011 1:23 pm, ZyX wrote:
> > Consider the following script:
> > % cat > expr-feedkeys.vim <<EOF
> > set nocompatible
> > let g:n=0
> > function FeedKeys()
> >
> > call feedkeys("i".g:n."\e")
> > let g:n+=1
> > return ""
> >
> > endfunction
> > nnoremap <expr> a FeedKeys()
> > nnoremap b :call FeedKeys()<CR>
> > EOF
> > % vim -u NONE -S expr-feedkeys.vim -s <(echo 'ab:wq! text')
> >
> > This will create file `text' that contains the only character `1' (and
> > NL, of
> > course), while expected to have two characters: `0' and `1'. Tested on
> > vim-7.3.102 (from Gentoo repos) and vim-7.3.138 (mercurial rev
> > ea399ac2c1b9).
>
> I think, expr-mappings don't see the typeahead until after the mapping
> finished. If you want to use feedkeys() inside an expression mapping, you
> need to return the feedkeys call, e.g (untested):
> return ':call feedkeys("i".g:n."\e")'."\n"
>
> regards,
> Christian
signature.asc
Description: This is a digitally signed message part.
