Reputation: 21
When editing JavaScript inside a script tag the syntax highlighting is much better than when editing myFile.js.
Is there a way to have the same syntax highlighting in a separate file as you have inside a script tag?
I already tested both the stock javascript.vim syntax file and this alternative one: http://www.vim.org/scripts/script.php?script_id=1491!
edit: please check screen shot:
Left side is inside script tags and :setfiletype html. Right side is plain javascript with :setfiletype javascript
Upvotes: 2
Views: 4067
Reputation: 1
In my case installing jelera/vim-javascript-syntax did the trick since vim-javascript plugin by itself didn't apply a nice color syntax. If your language of choice is Javascript (as in my case) I recommend you to follow this great guide. Hope this helps!
Upvotes: 0
Reputation: 2302
I know it's been a couple of months, but I wonder if you've found a satisfactory answer yet?
I found the following via :help syntax within vim:
JavaScript and Visual Basic embedded inside HTML documents are highlighted as 'Special' with statements, comments, strings and so on colored as in standard programming languages. Note that only JavaScript and Visual Basic are currently supported, no other scripting language has been added yet.
This seems to explain why everything that is does not have its own coloring in javascript.vim is colored "Special" when embedded within HTML. This seems to include variable names, function and method names, and so forth. I like it, too, because it separates variables, etc, from punctuation, etc. Much easier to see that your code is correct.
Upvotes: 1
Reputation: 6983
My vim JavaScript highlighting is awesome, this is my setup:
syntax on
filetype plugin on
syntax enable
au BufRead,BufNewFile *.js set filetype=javascript
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
with the following js-related bundles
jslint
and no specific syntax files
My colorscheme (molokai) takes care of the rest
Hope this helps you
Upvotes: 0