Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim syntax/compile-time error highlighting

Is there a Vim script that periodically tries to compile/interpret the code that I'm working on, and highlights syntax errors? I'd like it to point out that something is wrong between these lines:

int a = 42
cout << a << endl;

Such a thing would save me loads of time. I'm primarily searching for a Perl-syntax checker, but I'd also be interested in similar plugins for other languages.

Update: Another error I'd like it to point out:

int a == 42;
cout << a << endl;
like image 398
Tim Avatar asked Mar 11 '11 07:03

Tim


2 Answers

You can use eclim : once your eclim server is set up and running, you can use the Vim command :Validate to run a code validation on your file.

Basically, it uses the validation available in eclipse and display it in Vim/gVIm in the location list. (use :lopen )

For your example, the location list contains :

test.cpp|1 col 11 error| Syntax error
test.cpp|2 col 1 error| Syntax error

(the col 11 corresponds to location of the missing ;)

By default the validation is run every time you save a buffer.

The error description are not really crystal clear but once you find the line with the error, you usually spot the error pretty easily.

like image 80
Xavier T. Avatar answered Sep 29 '22 07:09

Xavier T.


Auto-indenting should do it. When you start your new line with an extra indentation level it probably means that either you entered a new block or that you did not finish a statement.

like image 35
Benoit Avatar answered Sep 29 '22 07:09

Benoit