I have a problem similar that for which nnoremap was conceived, but for the BufWrite aucmd.
I have a code formatter which isn't very well-behaved. Gnatpp demands to read a file directly rather than be fed stdin and output stdout as is the norm for code formatters.
First I tried this:
autocmd BufWrite *.ad[sb] Autoformat
But the problem is that, while 'Autoformat' itself works fine, it reads the file contents before writing. Hence, it makes it impossible to change any Ada source files anymore! How can I prepend an operation to this to 'write but without executing this autocmd' ?
As suggested, I have also tried BufWritePost instead, which allows one to change the file, but not I need to do
:w twice - the first time, the buffer is changed after writing the file, and the second write will write the formatting changes.