Vim, python pep8 and pylint.

Posted by Drakonen on April 13, 2010 in Uncategorized | Short Link

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*=/ =/

Facebook Twitter Email

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Copyright © 2005-2012 Draakwired All rights reserved.
The Shades theme, version 1.7, is a BuyNowShop.com creation.

Social links powered by Ecreative Internet Marketing