Linting your code, the vanilla way
You may want a linter plugin to lint your code in Vim but you probably don't need it. At least try the built-in way before jumping on the plugin bandwagon.
autocmd FileType <filetype> setlocal makeprg=<external command>
This autocommand tells Vim to use
<external command> when invoking
:make % in a
<filetype> buffer. You can add as many similar lines as needed for other languages.
The whole point of defining
makeprg is for Vim to parse the output of the linter and display eventual errors.
The most sensibly designed compilers/linters default to or can be told to use a simple, machine-readable, output formatting that looks more or less like this:
path/to/file:123:4 Error message
That format (and a few variants) is supported by default so there is no need to do anything but some compilers/linters are not as sensibly designed and you might have to handle silly formatting with ASCII arrows, multi-line messages, etc. In such a case, writing a custom
errorformat is pretty much an obligation. See
:help errorformat for the nitty-gritty.
Chances are your linter is already natively supported via the "Compiler" feature, in which case you don't have to define either
errorformat. You simply need to call the
:compiler command with the name of your linter as argument and you are set:
Of course, calling that command manually for every file you edit is not an exciting prospect but you can use an autocommand like the ones above to make it all automatic:
There are currently 96 supported "compilers" so it might be a good idea to
:view $VIMRUNTIME/compiler (and consider adding it to the default distribution if it is not ;-)).
Automatic execution on
autocmd BufWritePost <pattern> silent make! <afile> | silent redraw!
This autocommand tells Vim to run
:make on the current file matching
<pattern> whenever you
:write it. You can add patterns if you want that to happen with other filetypes.
autocmd BufWritePost *.py,*.js silent make! <afile> | silent redraw!
Automatic opening of the quickfix window
This autocommand tells Vim to open the quickfix window whenever a quickfix command is executed (like
:make) AND there are valid errors to display.
autocmd QuickFixCmdPost [^l]* cwindow