Linux 如何在vim中使用pylint

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3839454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:32:42  来源:igfitidea点击:

how to use pylint in vim

linuxvimsedpylint

提问by guilin 桂林

I do not want to install another plugin, like pylint.vim,

我不想安装另一个插件,比如 pylint.vim,

And today, I decide to use vim edit python instead of pydev which is a eclipse plugin. But I got issues.

今天,我决定使用 vim edit python 而不是 pydev 这是一个 eclipse 插件。但我遇到了问题。

I have add this in my vimrc

我已经在我的 vimrc 中添加了这个

autocmd BufWritePost *.py !pylint <afile>

but pylint does not contains filename in output

但 pylint 在输出中不包含文件名

************* Module mymodule
E: 22: invalid syntax

shell return 2

so it can not jump to the line 22 , so I use sed change the output

所以它不能跳到第 22 行,所以我用 sed 改变输出

autocmd BufWritePost *.py !pylint <afile> | sed 's/^\(\w*\):\s*\([0-9]\+\)/<afile>:: : /g'

it returns:

它返回:

mymodule.py:22: E: : invalid syntax

but without shell return 2 by vim. so it still can't jump to that line. vim consider it as compile successfully

但没有 shell 返回 2 vim。所以它仍然无法跳到那条线。vim 认为它编译成功

========================= new comment =========== Call a function in Vim's `autocmd` command

======================== 新注释 ============ 在 Vim 的 `autocmd` 命令中调用一个函数

I think maybe I should use make command and set makeprg, so I use below config

我想也许我应该使用 make 命令并设置 makeprg,所以我使用下面的配置

autocmd FileType python let &makeprg='pylint <afile> | sed s/^\(\w*\):\s*\([0-9]\+\)/<afile>:: : /g'
autocmd BufWritePost *.py make

when I save, vim returns:

当我保存时,vim 返回:

************* Module count
E:  3: invalid syntax
(1 of 2): ************* Module count
Error detected while processing BufWritePost Auto commands for "*.py":
E492: Not an editor command:  sed s/^\(\w*\):\s*\([0-9]\+\)/<afile>:: 
: /g 

采纳答案by jceb

why so complicated with sed which just works properly on Linux? Try the following:

为什么 sed 如此复杂,它在 Linux 上可以正常工作?请尝试以下操作:

set makeprg=pylint\ --reports=n\ --output-format=parseable\ %:p
set errorformat=%f:%l:\ %m

回答by Reactormonk

pylint.vimis old, use syntastic instead:

pylint.vim是旧的,请改用 Syntastic:

https://github.com/scrooloose/syntastic

https://github.com/scrooloose/syntastic

回答by guilin 桂林

at last I resolve it myself. I'd like share with you guys. 2 lines in vimrc.

最后我自己解决了。我想和你们分享。vimrc 中的 2 行。

autocmd FileType python let &makeprg='pylint %\|sed "s/^\(\w*\):\s*\([0-9]\+\)/%::\ :\ /g"'
autocmd BufWritePost *.py make 

回答by gurney alex

you may want to try running epylint instead of just pylint.

您可能想尝试运行 epylint 而不仅仅是 pylint。

epylint (shipped with pylint) is the one that is used within emacs (with flymake). It has a few changes, especially regarding path handling, see the docstring at the start of pylint/epylint.py for more information. It may help you in vim too.

epylint(与 pylint 一起提供)是在 emacs(与 flymake 一起)中使用的。它有一些变化,特别是关于路径处理,请参阅 pylint/epylint.py 开头的文档字符串以获取更多信息。它也可以在 vim 中帮助您。

Sidenote: I'm not a vim user for programming myself, but pylint.vim still seems to be a decent option. But I won't question your prerequisites.

旁注:我不是自己编程的 vim 用户,但 pylint.vim 似乎仍然是一个不错的选择。但我不会质疑你的先决条件。

回答by khushbu

autocmd FileType python let &makeprg=‘/usr/local/bin/pylint %'

autocmd FileType python let &makeprg='/usr/local/bin/pylint %'

autocmd BufWritePost *.py make

autocmd BufWritePost *.py make

autocmd FileType python let &makeprg=‘/usr/local/bin/pyflakes %'

autocmd FileType python let &makeprg='/usr/local/bin/pyflakes %'

autocmd BufWritePost *.py make

autocmd BufWritePost *.py make

回答by iamdi

I would recommend to use A.L.E (Asynchronous Lint Engine) https://github.com/w0rp/ale

我建议使用 ALE(异步 Lint 引擎)https://github.com/w0rp/ale

It supports a range of python linters and formatters including pylint. Great thing about A.L.E that it supports many other languages.

它支持一系列 python linter和格式化程序,包括pylint。ALE 的一大优点是它支持许多其他语言。