I want to be able to lint my code from within vim, using tools like clang-format
and yapf
and I'd rather do this without installing a more complex plugin.
I can pipe the current buffer through a text processing command:
:%!clang-format
However, if my buffer contents results in an error for the external command, my buffer will be replaced with stderr output and I will have to reset this manually (with an undo).
Is there any way to only replace the buffer if the text-processing command returns exit success?
I know I can undo but, ideally, I would like to be able to run this on vim exit but I can't risk the buffer being clobbered. This has other applications than linting, so a more general solution than just install the xxx plugin would be appreciated, if anyone knows of one!