Halim, Salman wrote:
You can have something happen on multiples of CursorHold and CursorHoldI
by doing something like this (untested):

:let g:flag = 0
:au CursorHoldI * if g:flag == 1 | doSomething | let g:flag = 0 | else |
let g:flag += 1 | endif

The 'doSomething' bit should only happen every other CursorHoldI firing.
You could change the if condition to work off a higher number if you
want.

I have a (relatively) complicated function called LongEnough that return
true/false if it has either been sufficiently long since the last time
it was called or if it has been called quite frequently.  Useful if you
want to execute something either every 5 seconds or every 3 calls, for
example.  I can share it if it'll help.

Salman.

I've always been told that CursorHold doesn't fire again if you don't hit the keys after it has fired, and that CursorHoldI is "just like CursorHold but for Insert mode".

Here's a testcase:

set laststatus=2
hi StatusLine ctermbg=green ctermfg=white guibg=red guifg=black
let s:statuslineflag = 0
function ToggleStatusLine()
        if s:statuslineflag
            hi StatusLine ctermbg=black ctermbg=white guibg=red guifg=black
        else
            hi StatusLine ctermbg=green ctermfg=white guibg=green guifg=white
        endif
        let s:statuslineflag = ! s:statuslineflag
endfunction
augroup togglestatus
        au! CursorHold,CursorHoldI * call ToggleStatusLine()
augroup END

With this code, does the active status line start blinking every 4 seconds when you stop banging at keys? In my version of Vim, it doesn't (instead, it changes colour once after 4 seconds of inactivity, and then not again until I hit a key); and that means that (with the code you showed) you can't both "save your work after 4 seconds of inactivity" and (let's say) "stop input mode after 12 seconds of inactivity" even though the latter is a multiple of the former.

... Nice visual effect; I'm gonna move it into my colour scheme.

See
        :help CursorHold
        :help CursorHoldI
        :help 'updatetime'


Best regards,
Tony.
--
"Benson, you are so free of the ravages of intelligence"
                -- Time Bandits

Reply via email to