7

Sometimes when I make coding mistakes I spend a lot of time finding the error.

Is there a plugin which makes Vim underline or highlight PHP, HTML or CSS mistakes?

For instance:

 <?php
 foreach ($row as $r) {
  <echo '<h1>' . $r->title . '</h1>';
 }
 ?>

The '<' before echo will be highlighted in red.

Vim has HTML correction but I need for PHP and CSS.

3 Answers 3

7

There is plugin for Vim, developed by the infamous scrooloose, called Syntastic that does exactly what you are looking for. It is described as:

A syntax checking plugin that runs buffers through external syntax checkers as they are saved and opened. If syntax errors are detected, the user is notified and is happy because they didn't have to compile their code or execute their script to find them.

The syntax checker is extended with language plugins and there just so happens to be one for PHP as well as HTML, although I'm not positive about CSS at the moment. Either way, as soon as you open a file or attempt to save one that has syntax errors, you can set up Syntastic to alert you in various ways:

* A statusline flag appears when syntax errors are detected
* |signs| are placed beside lines with syntax errors, where a different
  sign is used for errors and warnings.
* The :Errors command is provided to open a |location-list| for
  the syntax errors in the current buffer

Be sure to check out the helpdoc as there is a ton of useful info in there.

https://github.com/scrooloose/syntastic

Sign up to request clarification or add additional context in comments.

5 Comments

OK, I think syntastic is the perfect plugin for that (by the way, why is scrooloose infamous)?
@alexchenco, what romain1 said. The main answer was Syntastic, I just threw in the infamous part because I really appreciate scrooloose's contributions to Vim and wanted to give him some extra credit. And I used infamous instead of famous because it flows more with his persona.
I just added today a CSS syntax-checker to Syntastic, using CSS Lint. It relies on CSS Lint's CLI tool, so you have to install it.
Has anyone actually seen Syntactic work? I can't find a single SO topic where the guy/girl manages to get his/her vim to do syntax checking.
@puk, I use it daily for error checking PHP and C and it works wonders. What exactly is the problem?
1

This Runtime syntax check for php may help you.

Comments

-1

No. vim only has syntax highlighters, not syntax validators. It's about time you switch to something like Eclipse - it even has the VIM shortcuts extension now.

8 Comments

@m1tk4 Yes is a good idea but I'm not sure if I can survive without Vim's key bindings.
-1, vim's syntax highlighting is flexible enough to catch this kind of issue. So a custom style to do this is quite feasible.
@michael anderson : Please read the question again - it was about AVAILABILITY, not feasibility. We all know you can build a kitchen sink in both vim and emacs.
@m1tk4 - the syntax highlighters for C/C++, PHP, HTML highlight certain kinds of syntactic errors. Saying that it doesn't have any syntax validators is misleading. Using that to then promote your editor if choice is obnoxious
-1, This is such a misleading saying. The chosen answer for this question is a proof of this. Vim has many plugins for syntax checking.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.