907th/vim-auto-save

Throttling / batching for InsertLeave and TextChanged

gunar opened this issue · 2 comments

gunar commented

Hi! It'd be great to have an option to enable throttling when having this config

let g:auto_save_events = ["InsertLeave", "TextChanged"]

Context: I use a file watcher tool, and if too many changes are made in a short interval, sometimes it doesn't catch the latest change. If vim-auto-save could batch changes every 500ms, that'd be perfect.

Thank you so much for this awesome piece of software. I couldn't picture myself coding without it.

907th commented

@gunar Thanks for your support!

Regarding your idea of throttling auto-saves: I don't think that this is a good idea (especially for InsertLeave/TextChanged events) because the cool stuff about InsertLeave is that it happens instantly after changes made by user. Furthermore, I think that implementing a throttling in vim-auto-save would make the plugin code overcomplicated. Sorry if my answer upset you.

I understand you problem. These are solutions I can think right now:

  • (easier) Try to use another events, e.g. CursorHold + CursorHoldI and set updatetime option to 500ms.
  • (harder) May be you would like to try to implement a throttling by yourself, right in your .vimrc file using VimScript.
gunar commented

Thanks Alexey! Using the CursorHold event solved my problem.