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,@htmlPreproc
The 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,@htmlPreproc
syn region javaScriptStringS start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=javaScriptSpecial,@htmlPreproc
One 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 :-/