Vim and PEP 8 — Style Guide for Python Code

2019-02-02 03:20发布

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).

5条回答
霸刀☆藐视天下
2楼-- · 2019-02-02 03:30

As of 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.


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.

Old Answer (2013)

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

查看更多
爷、活的狠高调
3楼-- · 2019-02-02 03:32

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

查看更多
Lonely孤独者°
4楼-- · 2019-02-02 03:44

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/

查看更多
等我变得足够好
5楼-- · 2019-02-02 03:45

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

查看更多
Animai°情兽
6楼-- · 2019-02-02 03:51

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.

查看更多
登录 后发表回答