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

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.

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.

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!

Related

Any preferably open source html compressor written in Javascript?

I am looking for an HTML compressor/minimizer written in Javascript. Say, I have a Javascript variable containing some HTML code, I want to pass it to a Javascript function that will remove unecessary spaces, comments, etc... Does such tool exist? I can't find any...
Is there a specific reason for a javascipt minimizer?
If you are worried about your website loading time, then why not try head.js()?
You can see the change if you have a large number of libraries.
But if you have really want to minify, there is AJAX minifier
I used it just now and works wonderful.

How to find unused/dead code in web projects (90% code in javascript)

I did find a very interesting tool for identify unused css definitions in a web project.
http://www.sitepoint.com/dustmeselectors/
Are there similar tools also for javascript projects?
P.S.
I know there is no program for deterministically finding unused code. But I am looking for a report to identify possible unused code. Then the last decision will always be your own.
Problem is there is no way to be really sure. Suppose the following:
The initial HTML site is practically empty. There is a lot of JS code though, which seems to be unused.
OnLoad, a function is called which launches an AJAX query to the server. The server returns a lot of HTML code, which is the body of the site. This body contains lots of JavaScript functions.
The initial body is replaced with the body received via AJAX. Suddenly, all code is used.
Static analysis utilities are therefore useless. I do not know whether there exists a browser extension that marks all JS usage from a running browser though.
You can try using tombstones to safely locate and remove dead code from your JavaScript.
https://blog.bugsnag.com/javascript-refactoring-with-bugsnag-and-tombstones/
In order to find the unused assets, to remove manually, you can use deadfile library:
https://m-izadmehr.github.io/deadfile/
It can simply find unused files, in any JS project.
Without any config, it supports ES6, JSX, and Vue files:
The one that comes to mind most quickly is Javascript LINT (http://www.javascriptlint.com/) and JSLint (http://www.jslint.com/).
Beware though: the latter hurts your feelings.

Aptana //novalidate option

I'm writing Processing.js code using Eclipse (with the Aptana plugin), and I'm a little confused by this option in the Javascript preferences:
Enable error filtering inside //novalidate comments
Using Processing.js allows me (and occasionally forces me - for example, it uses the Java "void" instead of the Javascript "function" for method declarations) to do some funky things to javascript syntax that the validator doesn't like. I've got a bunch of error messages that I'd like to silence, but I'd rather use the Eclipse editor because the rest of my site is there.
I've tried sticking "//novalidate" before, after, after the semicolon on the same line, and even at the beginning of the file, but it has no effect. I've also tried adding exclude rules in Preferences -> Validation, but that doesn't seem to do anything, nor does turning off "Javascript problems" in Problems -> Configure Contents... (which I'd like to avoid, because I'm doing regular javascript elsewhere on my site). I can't find any documentation for "//novalidate" on the Aptana website - does anyone have any idea how to use this properly?
Thanks in advance.
Have you tried Aptana Support methods?

Aptana and JavaScript/jQuery IDE

I'm using Aptana for JavaScript and jQuery.
My script files are not being outlined, but I understand that this is a known issue.
When editing JavaScript, is there a way to add simple editing short cuts like:
High light a block and comment /or uncomment block.
Getting intellisense to recognize Jquery-UI and other libraries?
And while I’m here and asking what about the outliner and created code?
a. What allows JQuery to be recognized and my scripts to not be recognized?
Answers to 2. and a.
Aptana cheats. It knows jQuery and uses some local heuristics to guess when something is a jQuery collection, but it does not do data-flow analysis on the javascript to determine the type. That's why jQuery shows up, but jQueryUI and your code don't.

VS2008: Is there a way to enable bracket matching for javascript?

The bracket matching in VS2008 is a handy feature, but doesn't seem to work for javascript code.
Is there a way to enable it?
If VS can do this its news to me. It also has other annoyances like not allowing you to go directly to a js function (like you can with C#/VB code/CSS)
I'm currently building a web app (client side code heavy) and given up editing js in VS2008 - it just works against me.
Instead I do it all with notepad++ and the functionlist plugin. Upside is that it provides the bracket matching you're after and also splits all my functions out nicely for easier navigation, highlights the code correctly etc.
I don't see using another app as a problem as its only an alt-tab away
Notepad++
Notepad++ Plugin List
I have looked for similar solutions within VS itself but they either don't work exactly how I'd like or (in one case) crash VS.

Categories

Resources