[英]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 文件时,只有那些(我想保留所有其他文件类型的配置)。
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.它基于语言服务器协议。
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 检查,而且通过安装其他软件,可以很容易地为其他语言添加语法检查等。
vim-flake8
is the better choice, I will try it :-) vim-flake8
是更好的选择,我会试试的 :-)
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-pathogen或Vundle最容易设置。
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 错误和警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.