Vim: write back my file on each key press

前端 未结 6 456
孤街浪徒
孤街浪徒 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:32

    One hack is to use your status line:

    function! WriteFile() 
      if &buftype == ""
        write
      endif
      return '%f %h%w%m%r%=%-14(%l,%c%V%) %(%P%)'
    endfunction
    setlocal statusline=%!WriteFile()
    set laststatus=2
    

    As long as the status line is visible, it's updated after each change to the file. When updated, the WriteFile() function is called, which writes the file (and returns my approximation at the default status line). With laststatus=2, the status line is shown even when only one window is open.

    This will keep the current buffer saved after each change.

提交回复
热议问题