Currently I have JavaScript (.js) files that contain multiline strings. Vim's syntax highlighting does not seem to support these, as seen in the image below:Anything below the first line is not properly recognized as a string, and everything after the end quote is incorrectly considered a string. Any way to fix this?
How can I get syntax highlighting to support multiline JavaScript strings?
syntax highlighting;line breaks;filetype javascript
The /usr/share/vim/vim74/syntax/javascript.vim uses this to define what a string region is in Javascript:syn region javaScriptStringD start=++ skip=+\\\\\|\\+ end=+\|$+ contains=javaScriptSpecial,@htmlPreprocThe end option matches either the  character, or the end of the line $, which is why the syntax highlighting stops after the first line.We can override this by making a ~/.vim/after/syntax/javascript.vim file with:syn region javaScriptStringD start=++ skip=+\\\\\|\\+ end=++ contains=javaScriptSpecial,@htmlPreprocsyn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=javaScriptSpecial,@htmlPreprocOne line for strings, and another for 'strings'. We just removed the |$ part (| for or, $ for end of line).Note: I think it would be better to only highlight the string if the previous line escapes the \n (ie. ends with \). I happen to know that the C syntax does this, but I can't seem to steal borrow that and get it working in Javascript :-/