I found the following code snippet on the internet, and want to use it in my own .vimrc.
augroup CodeFormatters
autocmd!
autocmd BufReadPost,FileReadPost *.py :silent %!PythonTidy.py
augroup END
However, I’m not quite sure where to put the PythonTidy.py script, so that it is accessible from everywhere.
Furthermore I read that using BufReadPre is better than BufReadPost, respectively FileReadPre, is that true?
As it stands,
PythonTidy.pymust be accessible through yourPATH. If you have a convenient place already contained in there, e.g.~/bin, just place it there.Alternatively, you can place it somewhere into your
.vimdirectory, and use something likeexpand('<sfile>:p:h')to resolve the directory of your Vimscript, and build a relative path from there.As you want to filter the read buffer contents with the
:%!command, you have to use theBufReadPostevent; withBufReadPre, the buffer hasn’t yet been read and nothing would be sent to the filter.