Kljunas2
Kljunas2

Reputation: 66

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.

Upvotes: 1

Views: 99

Answers (1)

kosciej16
kosciej16

Reputation: 7128

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

Upvotes: 2

Related Questions