views:

54

answers:

1

This is related to http://stackoverflow.com/questions/3232518/how-to-update-vim-to-color-code-new-html-elements, but I want the syntax highlighter to only highlight the elements if it detects the html5 doctype at the first line of the file. Is there an easy way to do this?

+2  A: 

You would add something like this to the top of the html.vim syntax file:

if getline(1) =~? '<!DOCTYPE html>'
  let b:html5 = 1
else
  let b:html5 = 0
endif

And then throughout the syntax file you can use if b:html5 to check if html5 is being used for the current buffer.

if b:html5
  " new html 5 tags
  syn keyword htmlTagName contained video canvas
endif
too much php
This is pretty great. I assume the =~? '' bit would be replaced with either a regex or a string, i.e., =~? '<!doctype html>'?
wilsona
Yes, sorry the angle brackets made everything disappear.
too much php