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?
Asked
Active
Viewed 1,175 times
6
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
– romainl Jul 11 '12 at 05:58:w ` which does what I need and not more. -
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 Answers
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
-
That directs you to todo.txt; as of Vim 7.3.584, it's not implemented yet. Volunteers welcome :-) – Ingo Karkat Jul 11 '12 at 13:47
-