views:

60

answers:

3

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 =========== http://stackoverflow.com/questions/1766336/call-a-function-in-vims-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 
+1  A: 

http://www.vim.org/scripts/script.php?script_id=891

Tass
Something a little more substantial than just a bare link would get an upvote.
Daenyth
Little more is bloat.
Tass
It protects against link rot.
Dennis Williamson
A: 

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

autocmd FileType python let &makeprg='pylint %\|sed "s/^\(\w*\):\s*\([0-9]\+\)/%:\2:\ \1:\ /g"'
autocmd BufWritePost *.py make 
guilin 桂林
I have use what jceb's answer
guilin 桂林
+1  A: 

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

set makeprg=pylint\ --reports=n\ --output-format=parseable\ %:p
set errorformat=%f:%l:\ %m
jceb
thanks. Just what I want. but, what's the mean of %:p. and the errorformat is a vim variable, how could it affect pylint?
guilin 桂林
guilin 桂林