简体   繁体   中英

Vim: inline JavaScript syntax highlighting better than on a separate file

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

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.

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!

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

Use vim-javascript . It works pretty well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM