如何在 Vim 的 Syntastic 中将 Python 最大允许行长度设置为 120?

How can I set the Python max allowed line length to 120 in Syntastic for Vim?

我将 python-mode 用于 Vim,我更喜欢有 120 个字符行,而不是 PEP8 标准中定义的 80 个字符行。

在python模式下,这很容易。我只是将以下内容添加到我的 ~/.vimrc:

" Pylint configuration file
let g:pymode_lint_config = '$HOME/.pylint.rc'
let g:pymode_options_max_line_length=120

这很好用,但是,我还想使用出色的 Syntastic 插件来检查各种其他类型的语法(例如,foodcritic 的 Chef 食谱。)

不幸的是,Syntastic 也做 Python linting,因此它现在开始抱怨我的 120 个字符行。有没有类似的东西我也可以做,让它不再抱怨我稍长的线路?

您可以向每个 linter 传递额外的参数。 对于pylint,你可以使用:

let g:syntastic_python_pylint_post_args="--max-line-length=120"

这现在在 linux 中的 ~/.config/flake8 和 windows 中的 ~/.flake 中全局配置。该文件可能如下所示。

[flake8]
max-line-length = 120

查看每个项目设置的文档:http://flake8.readthedocs.io/en/latest/user/configuration.html#project-configuration

我建议您通过将此行添加到您的 .vimrc 点文件来禁用长度检查:

let g:pymode_lint_ignore = "E501,W"

在您的虚拟环境文件夹中有一个名为 - defaults.py 的文件 - ......./lib/python3.6/site-packages/flake8

您可以更改该文件中 max-line-length 的值。