Re: automatically enter normal mode
John Little wrote: Hi all No one has mentioned the feedkeys() work-around (ahem, swallow) for this, if you want periodic events. For example, function! Timer() echo strftime("%c") let K_IGNORE = "\x80\xFD\x35" " internal key code that is ignored call feedkeys(K_IGNORE) endfunction au CursorHold,CursorHoldI * :call Timer() turns vim into a clock. It doesn't work in visual, command, and operator pending mode. I use it as a tail -f viewer (replace the echo with checktime | normal G) for log files I want to have syntax highlighted, a practice I find really helpful. Regards, John Little If it works, it also turns the CursorHold[I] events frome one-shot timers to repeat clocks, so invoke the function (replacing the :echo by nothing) then trigger anything that must be called repeatedly from _another_ CursorHold,CursorHoldI autocommand (which may be defined in a different script). If this timer autocommand is defined in its own augroup (let's say timerrepeat) you can turn it off easily: ":au! timerrepeat". Warning: It is possible that some plugins expect the CursorHold[I] events to fire only once in periods of inactivity of any duration. Best regards, Tony. -- Said a horny young girl from Milpitas, "My favorite sport is coitus." But a fullback from State Made her period late, And now she has athlete's fetus
Re: automatically enter normal mode
Hi all No one has mentioned the feedkeys() work-around (ahem, swallow) for this, if you want periodic events. For example, function! Timer() echo strftime("%c") let K_IGNORE = "\x80\xFD\x35" " internal key code that is ignored call feedkeys(K_IGNORE) endfunction au CursorHold,CursorHoldI * :call Timer() turns vim into a clock. It doesn't work in visual, command, and operator pending mode. I use it as a tail -f viewer (replace the echo with checktime | normal G) for log files I want to have syntax highlighted, a practice I find really helpful. Regards, John Little
Re: automatically enter normal mode
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
Re: automatically enter normal mode
Eric Smith wrote: On 08/05/07, A.J.Mechelynck <[EMAIL PROTECTED]> wrote: In an autocommand, you need an ex-command, which isn't. I suggest :au CursorHoldI * stopinsert Make sure 'updatetime' has a long enough value (the default is 4000, i.e., 4 seconds, which might be a little short for some people). Problem now is that I already have: au CursorHoldI * update and this wants an updatetime of 4000 while as you say stopinsert will want a higher number. Is there a way? Thanks Eric If you can bear to have insert mode stopped after you stopped banging at keys for "only" four seconds, or if you can bear to have the autosave happen not four seconds after you stopped banging at keys but after some more delay, then there is a way. (I would suggest 10 seconds but YMMV.) If you want a fast auto save _and_ a slow stopinsert, then it isn't obvious how to do it, since the CusorHoldI event will fire _once_ when you're in Insert mode and haven't been using the keyboard in Vim for 'updatetime' milliseconds, and then it won't fire again until you hit a key. (I think clicking the mouse counts as "hitting a key" in this context but I'm not 100% sure.) Best regards, Tony. -- If God had not given us sticky tape, it would have been necessary to invent it.
RE: automatically enter normal mode
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. > -Original Message- > From: Eric Smith [mailto:[EMAIL PROTECTED] > Sent: Tuesday, May 08, 2007 5:17 PM > To: vim@vim.org > Subject: Re: automatically enter normal mode > > On 08/05/07, A.J.Mechelynck <[EMAIL PROTECTED]> wrote: > > > In an autocommand, you need an ex-command, which isn't. I > > suggest > > > > :au CursorHoldI * stopinsert > > > > Make sure 'updatetime' has a long enough value (the default > is 4000, > > i.e., 4 seconds, which might be a little short for some people). > > Problem now is that I already have: > au CursorHoldI * update > and this wants an updatetime of 4000 while as you say > stopinsert will want a higher number. > > Is there a way? > > Thanks > > Eric >
Re: automatically enter normal mode
On 08/05/07, A.J.Mechelynck <[EMAIL PROTECTED]> wrote: In an autocommand, you need an ex-command, which isn't. I suggest :au CursorHoldI * stopinsert Make sure 'updatetime' has a long enough value (the default is 4000, i.e., 4 seconds, which might be a little short for some people). Problem now is that I already have: au CursorHoldI * update and this wants an updatetime of 4000 while as you say stopinsert will want a higher number. Is there a way? Thanks Eric
Re: automatically enter normal mode
Eric Smith wrote: I want a vim left in insert mode after n seconds of inactivity to automatically go into normal mode and tried: au CursorHoldI * But this gives an error. How? In an autocommand, you need an ex-command, which isn't. I suggest :au CursorHoldI * stopinsert Make sure 'updatetime' has a long enough value (the default is 4000, i.e., 4 seconds, which might be a little short for some people). Best regards, Tony. -- The only problem with being a man of leisure is that you can never stop and take a rest.
automatically enter normal mode
I want a vim left in insert mode after n seconds of inactivity to automatically go into normal mode and tried: au CursorHoldI * But this gives an error. How? -- Eric Smith