Santosh Kumar
Santosh Kumar

Reputation: 27875

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

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?

Upvotes: 6

Views: 1702

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172540

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

Upvotes: 4

Conner
Conner

Reputation: 31040

Take a look into :help autosave

Upvotes: 1

Related Questions