Monday, January 28, 2008

Embedded vi Syntax Highlighting


This is a vi syntax highlighting trick gmax
emailed to me. It changes the syntax highlighting for here documents and the
qq() and q() operators as long as braces {} are used to delimit them (that is the trick, you see). This example
'embeds' the MySQL highlighting scheme inside Perl code. Example.


Find the perl.vim file that is being used by your version of vi, usually somewhere
in /usr/share/vim/


Add this syntax to it:


syn include @Sql <sfile>:p:h/mysql.vim
syn region perlSQL start="qq{" end="}" contains=@Sql keepend
syn region perlSQL start="q{" end="}" contains=@Sql keepend
syn region perlSQL start="<<MYSQL" end="^MYSQL" contains=@Sql keepend

just before this line at the end of the file:
let b:current_syntax = "perl"

and save this file [mysql.vim] to the same directory
as the file you just edited (perl.vim).


No comments: