Search code examples
vimautocmd

Is there an autocmd-event that works on unmodified buffer with :x, but not :q


I want to autorun formatter when saving a file. Using BufWritePre doesn't work when quitting with :x (or ZZ), if the file hasn't yet been modified. ExitPre or QuitPre don't work either.


Solution

  • It's beacuse :x nor ZZ saves buffer when it's not modified. From documentation:

    :x          Like ":wq", but write only when changes have been
                made.
    

    If you would like to have it working on :x/ZZ you can map it to :wq which always saves buffer or use BufWinLeave