Grzegorz Wierzowiecki
Grzegorz Wierzowiecki

Reputation: 10843

Vim and PEP 8 -- Style Guide for Python Code

Could you recommend, how to configure Vim to stick to :

PEP 8 -- Style Guide for Python Code

when editing python2/3 files, and only those (I'd like to leave configuration as it is for all other filetypes).

Upvotes: 37

Views: 30322

Answers (5)

Dave Halter
Dave Halter

Reputation: 16325

As 2020

Using ale plus installing a linter pip3 install pylint is asynchronous and therefore probably the better idea. It does not block when you save, syntastic will block. It also works for other languages (like syntastic). It is based on the Language Server Protocol.


Old Answer (2014)

Using syntastic plus installing pip install flake8 gives you the best experience IMHO. syntastic is great, because it not only does pep8 checks for Python, but by installing other software it's really easy to add syntax checks and the like for other languages.

Old Answer (2013)

vim-flake8 is the better choice, I will try it :-)

Oldest Answer (2012)

There's also a little script called 'pep8' - https://github.com/vim-scripts/pep8

I have it configured on 8:

let g:pep8_map='<leader>8'

I really like it. It works really good.

Upvotes: 32

Aziz Alto
Aziz Alto

Reputation: 20311

I would recommend to use the inclusive klen/python-mode plugin.

Where you can use :PymodeLintAuto for PEP8 errors and warnings with every time you save your code.

Upvotes: 3

Kannan Mohan
Kannan Mohan

Reputation: 1840

Here is a vimrc configuration file which I prefer to use. It takes care of all PEP8 configuration.

Upvotes: 1

beltsonata
beltsonata

Reputation: 134

The answers are focusing on checking the style after source code has been written but the question seems to be about making vim stick to the pep8 style during editing itself.

The main problem I've had with vim and pep8 is indentation, which can be fixed using this vim script:

EDIT3: Fix the terrible English...

EDIT2: Whoops, wrong script! Fixed. http://www.vim.org/scripts/script.php?script_id=974

EDIT1:

The script has been forked on github:

https://github.com/hynek/vim-python-pep8-indent/

Upvotes: 11

Niklas B.
Niklas B.

Reputation: 95308

There's vim-flake8, which is most easily set up using vim-pathogen or Vundle.

Upvotes: 17

Related Questions