I don’t know if this is possible/sensible, but I was curious to know if I can have my strings in javascript files have html highlighting. I discovered that strings in php could have SQL syntax highlighting, so I believe it is possible.
But, I don’t know vim-scripting, so any help on this appreciated.
I am using the Better Javascript syntax.
PS: If there could be an option to turn it on and off while editing a js file, that would be wonderful
Thanks
Yes, it’s possible if you don’t mind some syntax file hacking. First you need to include the HTML syntax file from within the Javascript syntax file — see
:help syn-includefor info on that; second you need to declare that HTML syntax can be found inside of certain elements (i.e. strings). Third, if you want to have the option of enabling and disabling it, you can make those commands dependent on a global variable, and write some mappings that set or unset the variable and then reload the syntax file.For examples on how inclusion works, take a look at
syntax/html.vim(which includes the Javascript and CSS syntax files),syntax/perl.vim(which includes the POD syntax file), orphp.vim(which includes SQL syntax highlighting in strings, conditional on a global ariable).Edit: did some work on actually making this happen in my copy.
In the head of
syntax/javascript.vim, just belowsyn case ignore, addThen add
@javaScriptHTMLto thecontained=lists forjavaScriptStringDandjavaScriptStringS.Finally you have to edit
syntax/html.vimto prevent it from trying to includesyntax/javascript.vimif it was loaded from javascript: find the line that readsand change it to