2

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: enter image description here

Left side is inside script tags and :setfiletype html. Right side is plain javascript with :setfiletype javascript

1
  • Please, post screenshots: we don't know what you think is good or bad highlighting. Commented Feb 24, 2012 at 6:45

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I haven't yet found an answer. Thanks for chiming in. It does explain why it colors everything “Special”. Do you know if there is a way to make standalone code behave as if it was embedded? Thanks
Haven't found one yet: I mucked around with it (when I SHOULD have been writing actual code) after posting here. I tried setting "Normal" use "Special" highlighting, which only worked if I did it from the command line, and affected everything, including the tab titles, ruler bar, and so forth: pretty dumb. If I find a way to do it, I'll post here.
Yeah, that's the thing with Vim, it's infinitely configurable, and what a great thing it is for a craftsman to be able to tinker his tool. But that means you're never over and sometimes you have to get work done :)
0

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

1 Comment

Thanks, but that's similar to what I have here. I included a screenshot in the question, please check that out.
0

Use vim-javascript. It works pretty well.

4 Comments

Maybe I'm missing something, but this looks the same as the screenshot above.
Did you use the latest version on github? I updated it with a bugfix for your exact issue just 14 hours ago. (When I first answered this question, I hadn't realized that the fix had not yet been pushed.)
I did. I just reset my whole vim set up and it didn't work either. It's not a matter of indentation, but of syntax highlighting. What color scheme do you use? Would you mind posting your .vimrc? Thanks
Hi int3, I think I understand the problem better now. You're right, with your change, inline and standalone javascript are consistent. However, they are now both “wrong”. On inline javascript, things like function names, dollar sign, etc were being recognized as syntax “Special” and on standalone javascript syntax “Normal”. They are now both recognized as Normal. I'd like the opposite.
0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.