How do I repeat any command on regular interval in vim?
Question
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?
Solution
Take a look into :help autosave
OTHER TIPS
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow