4

I'm trying to write a plugin for vim with vimscript and I want to show some log for specefic time. like:

echo 'some log'
sleep 2
redraw!

When I use sleep and redraw, all of current window freezing for a while but I want sleep just for logs, not all vim window!
How can I do that?

mo1ein
  • 535
  • 4
  • 18
  • 2
    It's good to know that you got an answer on SO. But if your question is vim specific, you may find better/more answers at http://vi.stackexchange.com, which is a dedicated site or `vi(m)` questions. (I am not discouraging you to ask questions here. But since you even offered bounty, I think it was urgent for you. Hence the suggestion.) Good luck! – anishsane Feb 24 '21 at 04:29
  • @anishsane Oh I forgot it. That's a good idea, Thanks. – mo1ein Feb 24 '21 at 20:01

1 Answers1

5

sleep will always block. With VIM version 8 you can use timer instead. Here is a stripped down example should not block VIM:

echo 'some log'
let timer = timer_start(2000, 'LogTrigger', {})
func! LogTrigger(timer)
  silent! redraw!
endfunc
mo1ein
  • 535
  • 4
  • 18
okket
  • 2,031
  • 3
  • 11
  • 14
  • 1
    I think `timer_start(2000, 'LogTrigger', {})` is correct, because when you set `repeat : -1` that works forever and `redraw!` works multiple time and after call function multiple time, you can't see anything! – mo1ein Mar 03 '21 at 09:28