How do I cancel the write in the BufWritePre/FileWritePre auto command?
I already looked at this question and the proposed solution, throw, displays error messages, and I don’t want that. It should be transparent to the user that nothing got written, since I am displaying my own error message.
Just throw your own error message, then. I don’t think there’s another way around this; after all, the user expects the buffer to be written after issuing a
:w, so only an exception can prevent this.You might work around this by using a
BufWriteCmdhook and:setl buftype=acwrite, and write the buffer entirely on your own, but that’s a lot of (error-prone) effort, and if you intend to issue an error, anyway, go with the exception.