Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I repeat any command on regular interval in vim?

Tags:

vim

save

autosave

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?

like image 339
Santosh Kumar Avatar asked Jul 11 '12 05:07

Santosh Kumar


2 Answers

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
like image 147
Ingo Karkat Avatar answered Oct 02 '22 21:10

Ingo Karkat


Take a look into :help autosave

like image 22
Conner Avatar answered Oct 02 '22 21:10

Conner