inoremap <expr><F2> PeekCharTimeout(1000)?"you pressed key! ":"timeout! "
I hit a case when getchar(1) seemingly consumes a pressed key.
1. vim -u NONE -c 'so x.vim' # file x.vim is below
2. If you press i<F2> and wait, you get 'timeout!', so this part works OK.
3. The other branch, has problem: press i<F2> then quickly 123. You get:
you pressed key! 23
Note that '1' gets lost. We expect result 'you pressed key! 123'
Since I call only getchar(1) here I don't understand why one pressed
char gets lost.
Thanks
Yakov
" ----- x.vim
set nocp
inoremap <expr><F2> PeekCharTimeout(1000)?"you pressed key! ":"timeout! "
function! PeekCharTimeout(milli)
" non-consuming key-wait with timeout
let k=a:milli
while k > 0 && getchar(1) == 0
sleep 100m
let k = k - 100
endwh
return getchar(1)
endfun