Vim: write back my file on each key press

前端 未结 6 465
孤街浪徒
孤街浪徒 2020-12-24 08:56

I\'d like vim to automatically write my file as often as possible. The ideal would be every keystroke.

I need to save regularly so that my background build process wi

6条回答
  •  抹茶落季
    2020-12-24 09:56

    I suggest using the method I described in similar Save file after each edit in vim question:


    The CursorHold and CursorHoldI might help. According to docs:

    |CursorHold|        the user doesn't press a key for a while
    |CursorHoldI|       the user doesn't press a key for a while in Insert mode
    

    Those events fire only once after inactivity and depend on updatetime variable (default: 4000ms). So you can:

    :au CursorHold  :update
    

    Which will update current buffer file (i.e. save only if modified) after default 4 seconds of inactivity in Normal mode.

    Add autocommand for CursorHoldI if you want to get the same behavior in Insert mode.


    Setting CursorHold, CursorHoldI events along with very short updatetime will make vim save the file instantly after the edit.

提交回复
热议问题