6

Actually I want to autosave my current file, :w command writes the file so I thought that when I will repeat this command at regular interval (say each 30secs.) I will achieve what I want. But how can I do so?

Santosh Kumar
  • 24,301
  • 18
  • 65
  • 110
  • Crap. I had it setup once, but I scraped it before I put my vimrc under version control. It used updatetime, I think. But it created problems of its own that made autosave not worth it for me. Now I have `inoremap :w` which does what I need and not more. – romainl Jul 11 '12 at 05:58
  • Related: http://stackoverflow.com/questions/6991638/how-to-auto-save-a-file-every-1-second-in-vim?rq=1 – Ingo Karkat Jul 11 '12 at 13:45

2 Answers2

4

Vimscript itself is single-threaded; you cannot regularly execute a command per se. The closest to a periodic trigger are autocmds, especially the CursorHold event, which fires after no key has been pressed for 'updatetime', typically 4 seconds.

Another interesting event for auto-saving is FocusLost, but that one may not be triggered in the terminal, just in GVIM.

With it, something like this can be defined:

autocmd CursorHold,CursorHoldI <buffer> silent! write
Ingo Karkat
  • 161,022
  • 15
  • 231
  • 302
  • I googled around for this stuff a bit last night and there are some promising results (including a few specifically for auto-saving) that all use this `CursorHold` approach. – Wayne Jul 11 '12 at 14:43
1

Take a look into :help autosave

Conner
  • 28,826
  • 8
  • 50
  • 73