wilsona
wilsona

Reputation: 73

Dynamically Detect HTML5 in vim

This is related to 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?

Upvotes: 5

Views: 957

Answers (1)

too much php
too much php

Reputation: 90998

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

Upvotes: 4

Related Questions