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

-- 
You received this message from the "vim_dev" 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

Raspunde prin e-mail lui