This is a really old article, but I experienced the same thing: sometimes the syntax highlighting just stopped working when I looked at the javascript section in the .html file. As the OP mentions, a quick workaround was to scroll up and then the magic would start to stand out again.
Today I found the main problem and a good solution. In Vim, syntax highlighting uses context to get the correct highlight, where the context is determined by the previous lines. You can specify how many lines before the current line are used in the output :syntax sync minlines=200 . In this case, it will use up to 200 previous lines as context. You can use the entire file (which can be slow for long files) by running :syntax sync fromstart .
As soon as I found this, I added this line to my .vimrc :
autocmd BufEnter *.html :syntax sync fromstart
This way .html files will use the whole file as context. This way, the javascript section will always be highlighted correctly, regardless of how long the JS section takes. Hope this helps someone else!
jorgeh Dec 01 '16 at 17:52 2016-12-01 17:52
source share