Vim, python pep8 and pylint.
When you are making your Python code pep8 conformant or want to have a good pylint score and you are using vim, there are a few ways to make it easier and faster.
First you need to know a bit about the vim option -q. -q takes a filename as a argument, and vim then uses this file to jump to locations in files where the used tool has reported something. Vim expects a very simple format here.
Vim can take the output of the pep8 command:
pep8 --repeat --ignore=E501 *.py > ~/pep.txt
Then start vim with:
vim -q ~/pepepep.txt
Vim then opens with the first reported issue, to go to the next, use :cn.
Or you can temporarily map z to that for this vim session:
:map z :cn<cr>
Like with pep8, you can do the same with pylint, but you need to use the --format parseable argument:
pylint views.py -f parseable > ~/pep.txt
Some regexps for common formatting issues
Remove trailing whitespace all over the file:
:%s/\s\+$//
Remove whitespace in front of a ,
:s/\s*,/,/
Remove whitespace in front of an equal-sign, if any, add a space.
:s/\s*=/ =/
Never knew about the -q option. Wow, that’s an excellent vim gem. Thanks for the heads up!
here’s a shortcut:
$ vim -q <(pep8 –repeat path/to/file.py)