puk
puk

Reputation: 16752

How Do I get a syntax check to work in/with vim?

This question has been asked, in one form or another, a dozen times here, and it blows my mind how not a single one actually addresses how to configure syntastic or jslint such that it actually does what it is supposed to do (its README file is completely useless)

see here

Can anyone provide some step by step instructions, or a link to such instructions. I tried to install jslint and spidermonkey, and I got nowhere.


I managed to get the syntax check to work (thanks to romainl). A few things I learned along the way that may help anyone with a similar problem

  1. To build Javascript Lint look for the README file nested in jsl-x.x.x/src/README.html
  2. The build instructions are gmake -f Makefile.ref but gmake is the same thing as make so issue the command sudo ln -s /usr/bin/make /usr/bin/gmake
  3. jsl will now be found in jsl-0.3.0/src/Linux_All_DBG.OBJ/jsl. To make it generally accessible do something like: ln -s /whatever/jsl-0.3.0/src/Linux_All_DBG.OBJ /home/ForestGump/bin/jsl. More information here
  4. To check that jsl actually works find a test file ( here) then issue the command jsl -process test.js. It should list all the errors.
  5. To customize your command line, add this to your vimrc file set statusline=%{SyntasticStatuslineFlag()}

Upvotes: 4

Views: 2928

Answers (2)

Cody Poll
Cody Poll

Reputation: 8270

Setup vundle according to its README.

Put this into your .vimrc:

Bundle 'scrooloose/syntastic'

Then enter this command in vim:

:BundleInstall

That's it.

EDIT: Vundle has changed its syntax since I originally wrote this. Nowadays, you use

Plugin 'scrooloose/syntastic'

and then enter

:PluginInstall

Upvotes: 2

romainl
romainl

Reputation: 196476

What did you do? What works and what doesn't? Do you get error messages?

Here is what I did:

  1. Downloaded the jsl sources from the JavaScript Lint site.
  2. Built jsl and moved it somewhere in my $PATH.
  3. Checked if it worked by running it against a random .js file
  4. Downloaded and installed Syntastic as a Pathogen bundle.
  5. Typed :helptags /path/to/syntastic/doc because for some reason Pathogen's automatic help tags generation doesn't work for me.
  6. Read Syntastic's documentation: :help syntastic.

Steps 1 to 5 didn't take more than 3 or 4 minutes, maybe less.

Step 6 is obligatory, whatever new tool you try. RTFM.

I didn't have to configure anything beside these 3 lines in my .vimrc (and I believe the third is redundant):

let g:syntastic_auto_loc_list=1
let g:syntastic_disabled_filetypes=['html']
let g:syntastic_enable_signs=1

and customizing my statusline a bit with:

%{SyntasticStatuslineFlag()}

EDIT

Here is my statusline:

set statusline=%<\ %n:%f\ %m%r%y%{SyntasticStatuslineFlag()}%=line:\ %l\ of\ %L,\ col:\ %c%V,\ win:\ %{WindowNumber()}\ 

Don't copy it verbatim or you'll get some errors due to the function call at the end. There is a paragraph about that in syntastic's help.

END EDIT

After all that, 10 or 12 minutes if you count reading the documentation, I have a very helpful location list and signs poping up each time I save a .js file with syntax errors.

Upvotes: 2

Related Questions