Motivation
How often do you write the code, run it and see a syntax error message? I often. And how often, having found and correcting this error, do you see the similar message again by running the code?
I often…
There are several reasons for this:
- I am very inconsiderate
- I write in many languages
And nothing else, if it's just some kind of script or page and play the code quickly. And if this is something that would need to be restarted to reproduce it, to exit / exit somewhere, and so on. etc.
I put up with it and tried to be attentive when reviewing the code before launch. But sometimes it did not help. Source files are long and losing one other bracket is not difficult.
Options
For each language separately, there may be a plug-in to solve this problem under vim. For example, for js there is a bunch of pretty jslint wrappers. But all this is not universal and having become accustomed not to reread the js code, you forget to do it for ruby ... Of course, you can install many plugins for syntax checking - and this is the simplest way out, but under one condition ...
')
Decision
And the condition is: you don't know what
syntastic is .
The plugin is working, but as practice shows, not every beginner vim-er can start using it (again, this is due to carelessness and excessive instability). Therefore, I am writing this little article.
So to begin with the installation:
git clone github.com/scrooloose/syntastic.git
cd syntastic
rake install
# ruby
p -r * ~/.vim/
By default, the plugin does nothing. And the simplest thing you can do to make the plug-in work visible is to add the following command to .vimrc:
let g:syntastic_enable_signs=1
and restart vim (it is important to
add the setting to .vimrc and
restart vim). Errors and warnings will be marked with >> symbols on the red and yellow backgrounds, respectively, on the left side of the code. To read the error message, enter
:Errors
. The inconvenience is that the Errors window is not updated when you overwrite the buffer and to update it you will need to type the command again
:Errors
.
Farther
Attention : js-code check will not work until you copy the binary downloaded from
www.javascriptlint.com/download.htm to any folder specified in your PATH.
And do not forget to read the documentation in vim
:h syntastic
Solving problems with the plugin
For some languages, the
plugin does not show markers to the left of the line with an error. For such a case is in the syntastic statusline flag - this is another way to see the results of the plug-in. This chip is described in detail by
:h syntastic-statusline-flag
Checking shell script syntax may not work out of the box. The simplest solution is to add a
let b:shell = 'sh'
or
let b:shell = 'bash'
line to a .vimrc. After that, the markers may not work, but the syntastic statusline mentioned above reports errors in the code.