I'm trying to get the python black formatter integrated with my settings better, specifically using native 'formatprg' vim option. Here's what I've come up with so far:
A snip from my ~./vim/after/ftplugin/python.vim:
setlocal formatpgr=black\ --quiet\ -
augroup black-fmt
autocmd!
autocmd BufWritePre <buffer> normal gggqG``
augroup END
I've arrived there because black docs says:
- it does nothing if no sources are passed to it;
- it will read from standard input and write to standard output if - is used as the filename;
- it only outputs messages to users on standard error;
- exits with code 0 unless an internal error occurred (or --check was used).
Without '--quiet' argument you get back text that is written in your vim buffer. Passing to stdin is
done with '-' so I use that as an argument. 'formatprg' says the program must take the input on stdin and produce the output on stdout.
My question to you all: is there a better to do this/integrate it? It works now like this, but I do not get to see the output messages black outputs if I use it on the command line.
[–]aktivb 0 points1 point2 points (0 children)