Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use pylint in vim

Tags:

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

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

I have add this in my vimrc

autocmd BufWritePost *.py !pylint <afile> 

but pylint does not contains filename in output

************* 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

autocmd BufWritePost *.py !pylint <afile> | sed 's/^\(\w*\):\s*\([0-9]\+\)/<afile>:\2: \1: /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

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

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

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

when I save, vim returns:

************* 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>:\2:  \1: /g  
like image 812
guilin 桂林 Avatar asked Oct 01 '10 13:10

guilin 桂林


1 Answers

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

set makeprg=pylint\ --reports=n\ --output-format=parseable\ %:p set errorformat=%f:%l:\ %m 
like image 194
jceb Avatar answered Oct 26 '22 14:10

jceb