gui*_* 桂林 23 linux vim sed pylint
我不想安装另一个插件,比如pylint.vim,
今天,我决定使用vim edit python而不是pydev,这是一个eclipse插件.但我遇到了问题.
我在我的vimrc中添加了这个
autocmd BufWritePost *.py !pylint <afile>
Run Code Online (Sandbox Code Playgroud)
但是pylint在输出中不包含文件名
************* Module mymodule
E: 22: invalid syntax
shell return 2
Run Code Online (Sandbox Code Playgroud)
所以它不能跳到第22行,所以我使用sed改变输出
autocmd BufWritePost *.py !pylint <afile> | sed 's/^\(\w*\):\s*\([0-9]\+\)/<afile>:\2: \1: /g'
Run Code Online (Sandbox Code Playgroud)
它返回:
mymodule.py:22: E: : invalid syntax
Run Code Online (Sandbox Code Playgroud)
但没有shell返回2由vim.所以它仍然无法跳到那条线.vim认为它编译成功
=========================新评论=========== 在Vim的`autocmd`命令中调用一个函数
我想也许我应该使用make命令并设置makeprg,所以我使用下面的配置
autocmd FileType python let &makeprg='pylint <afile> | sed s/^\(\w*\):\s*\([0-9]\+\)/<afile>:\2: \1: /g'
autocmd BufWritePost *.py make
Run Code Online (Sandbox Code Playgroud)
当我保存时,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>:\2:
\1: /g
Run Code Online (Sandbox Code Playgroud)
jce*_*ceb 29
为什么如此复杂的sed才能在Linux上正常运行?请尝试以下方法:
set makeprg=pylint\ --reports=n\ --output-format=parseable\ %:p
set errorformat=%f:%l:\ %m
Run Code Online (Sandbox Code Playgroud)
Rea*_*onk 15
pylint.vim 是旧的,使用合成代替:
https://github.com/scrooloose/syntastic