Handling v:count in popup filters

9 views
Skip to first unread message

Lifepillar

unread,
Sep 3, 2020, 9:26:31 AM9/3/20
to vim...@googlegroups.com
How do you handle counts with a popup menu filter?

Something like this almost works:

let s:n = 0
fun MyFilter(winid, key)
if a:key == '+'
let s:n += v:count1
call popup_settext(a:winid, printf('Value: %d', s:n))
return 1
endif
return 0
endf

let id = popup_create('Value: 0',
\ #{ close: 'button',
\ border:[1,1,1,1],
\ filter: 'MyFilter'})

I can type, say, 5+ to have the counter increased by 5.

Unfortunately, v:count1 is not cleared after that, so if I type 3+ next,
the counter is increased by 53 instead of 3. Is there a workaround?

Thanks,
Life.


Reply all
Reply to author
Forward
0 new messages