How to install or upgrade Black in Vim 8 and format when saving?


This method of installing Black uses the built-in plugin management in Vim 8+.

sudo rm -rf ~/.vim/black
mkdir -p ~/.vim/pack/start/black/plugin
curl -o ~/.vim/pack/start/black/plugin/black.vim

Next time you open Vim, Black will install.

Add the following to ~/.vimrc to format with Black every time you save.

autocmd BufWritePre *.py execute ':Black'