简体   繁体   English

Vim 和 PEP 8 -- Python 代码风格指南

[英]Vim and PEP 8 -- Style Guide for Python Code

Could you recommend, how to configure Vim to stick to :你能推荐一下,如何配置 Vim 以坚持:

PEP 8 -- Style Guide for Python Code PEP 8 -- Python 代码风格指南

when editing python2/3 files, and only those (I'd like to leave configuration as it is for all other filetypes).编辑 python2/3 文件时,只有那些(我想保留所有其他文件类型的配置)。

As 2020作为 2020

Using ale plus installing a linter pip3 install pylint is asynchronous and therefore probably the better idea.使用ale plus 安装pip3 install pylint是异步的,因此可能是更好的主意。 It does not block when you save, syntastic will block.保存时不会阻塞,syntastic 会阻塞。 It also works for other languages (like syntastic).它也适用于其他语言(如语法)。 It is based on the Language Server Protocol.它基于语言服务器协议。


Old Answer (2014)旧答案 (2014)

Using syntastic plus installing pip install flake8 gives you the best experience IMHO.使用Syntastic加上安装pip install flake8给你最好的体验恕我直言。 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. syntastic很棒,因为它不仅可以对 Python 进行 pep8 检查,而且通过安装其他软件,可以很容易地为其他语言添加语法检查等。

Old Answer (2013)旧答案 (2013)

vim-flake8 is the better choice, I will try it :-) vim-flake8是更好的选择,我会试试的 :-)

Oldest Answer (2012)最旧的答案 (2012)

There's also a little script called 'pep8' - https://github.com/vim-scripts/pep8还有一个名为“pep8”的小脚本 - https://github.com/vim-scripts/pep8

I have it configured on 8:我在 8 上配置了它:

let g:pep8_map='<leader>8'

I really like it.我很喜欢。 It works really good.它真的很好用。

vim-flake8 ,使用vim-pathogenVundle最容易设置。

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 .这些问题的答案都集中在之后的源代码已被写入,但这个问题似乎是有关编辑过程本身使得VIM固守PEP8风格检查风格。

The main problem I've had with vim and pep8 is indentation, which can be fixed using this vim script:我在 vim 和 pep8 上遇到的主要问题是缩进,可以使用以下 vim 脚本修复:

EDIT3: Fix the terrible English... EDIT3:修复糟糕的英语...

EDIT2: Whoops, wrong script! EDIT2:糟糕,错误的脚本! Fixed.固定的。 http://www.vim.org/scripts/script.php?script_id=974 http://www.vim.org/scripts/script.php?script_id=974

EDIT1:编辑1:

The script has been forked on github:该脚本已在github上分叉:

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

I would recommend to use the inclusive klen/python-mode plugin.我建议使用包容性klen/python-mode插件。

Where you can use :PymodeLintAuto for PEP8 errors and warnings with every time you save your code.每次保存代码时,您可以在哪里使用:PymodeLintAuto来处理 PEP8 错误和警告。

Here is a vimrc configuration file which I prefer to use.这是我更喜欢使用的vimrc配置文件。 It takes care of all PEP8 configuration.它负责所有 PEP8 配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM