# Using pylint with Vim QuickFix

These days I almost exclusively work in dynamic scripting languages, so having a linter is really quite helpful. After the Nth time switching terminal windows out of vim to run pylint or jshint or some other such linter (where N is >> bajillions), I got tired of it and wanted to see how vim could integrate. QuickFix, as it turns out, is great, but frankly the documentation for the errorformat syntax could use some work, and I don’t think all of the formats out there, especially for pylint, are all that great.

This is what I have in ~/.vim/compiler/pylint.vim:

if exists('current_compiler')
finish
endif
let current_compiler = 'pylint'
CompilerSet makeprg=pylint\ -f\ parseable\ -r\ n\ %
CompilerSet efm=%A%f:%l:\ [%t%.%#]\ %m,%Z%p^^,%-C%.%#,%-GNo%.%#

It’s cobbled together from a few different sources, but mainly this Vimtip. The extra %-GNo%.%# bit at the end discards an extraneous pylint message if you don’t have a config file.

For ~/.vim/compilter/jslint.vim, I have the following, which is rather simplistic:

if exists("current_compiler")
finish
endif
let current_compiler = "jslint"
CompilerSet makeprg=jslint\ --terse\ %
CompilerSet errorformat=%f(%l):%m

I also got tired of typing :make and :cw all the time (the pain, I know), so I added the following line to my .vimrc:

nmap <leader>w :w<CR>:silent make<CR>:redraw!<CR>:cw<CR>

For some reason I have yet to figure out, :silent make causes weird display artifacts on my terminal, so the :redraw! is just a hack to fix that.

Update: From StackOverflow, a better JSLint compiler definition that can parse the column data in the verbose error messages to move the cursor to the correct location (the preamble is the same as above):

CompilerSet makeprg=jslint\ %
CompilerSet errorformat=%-P%f,
\%A%>%\\s%\\?#%*\\d\ %m,
\%Z%.%#Line\ %l\\,\ Pos\ %c,
\%-G%f\ is\ OK.,
\%-Q