Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Real SQL syntax highlighting in PHP scripts with Vim

I know it's possible to enable SQL syntax highlighting in PHP scripts using the option

let php_sql_query=1

But this just enables highlighting of all SQL keywords in every string. Even in a normal sentence like this one.

Is there a way to only enable this for strings starting with "Select", "update" or "delete"?

like image 360
Jonas Wouters Avatar asked Mar 13 '12 13:03

Jonas Wouters


1 Answers

Enclosing the query in a heredoc with an identifier of "SQL" triggers Vim to do SQL syntax highlighting in the block, e.g.:

$q = <<<SQL
        SELECT `foo`
        FROM `db`.`table`
        WHERE `foo` = 'bar'
SQL;
like image 92
Ellen Shull Avatar answered Nov 19 '22 10:11

Ellen Shull