pangloss / vim-javascript Goto Github PK
View Code? Open in Web Editor NEWVastly improved Javascript indentation and syntax support in Vim.
Home Page: http://www.vim.org/scripts/script.php?script_id=4452
Vastly improved Javascript indentation and syntax support in Vim.
Home Page: http://www.vim.org/scripts/script.php?script_id=4452
Hi,
I'm using htmldjango filetype (I guessed it's included in vim by default now) for my django projects. As soon as I started using vim-javascript indentation html indentation is slow and completely wrong. What can I do to fix this?
Hi,
I am not getting syntax highlight for try/catch
blocks. I am testing with a new .js
file with the following code:
try {
dataObj = JSON.parse(data);
}
catch (e) {
return callback(e);
}
I'm trying to get folds to include comments with the function fold, so that:
// Quick unction description
function() {
//...
}
/**
are folded into
-+- function() { .... } | Longer description here... ------
I know how to set the foldtext, but I'm having trouble overriding the fold definition to include both. I'm new to vimscript and so I'm hunting and pecking on my fork to accomplish this. I haven't had any luck so far, so I thought I'd just post the question because it might be way easier than I think.
Thanks for the module!
http://code.google.com/p/jsdoc-toolkit/wiki/TagReference
Seems as though the syntax files supports some of these doc tags. I'm wondering if it could support all of them? This seems to be the standard for JS documentation. If you want I can implement and give you a pull request if you are interested.
very correct indentation for javascript
could you give examples of differences between this plugin and the default? also, are you planning on merging this upstream?
It is jiving with another plugin of mine, and according to the help files it's set by vim automatically. Why are you manually setting it at the end of syntax/javascript.vim ?
I updated today and was rather bewildered when suddenly various statements were concealed with weird replacements.
That's a /really/ drastic step. Personally I can't imagine why anyone would ever want that but who knows maybe someone else will love it. In any case - you should really make that optional/configurable.
Several people have submitted good changes to this project lately. Rather than me continuing to act as gatekeeper, I'd be happy to open up commit rights to everyone who submits an accepted patch. Does anyone have any thoughts either way on the subject?
Regards,
Darrick
This works fine with double quotes, but not with single quotes:
app.get("/*", function (req, res) {
return null;
}
app.get('/*', function (req, res) {
return null;
}
Hi,
I was wondering what issue cc074c3 fixes. (I'm not at all versed in vim syntax highlighting)
This commit has broken some of the syntax highlighting for my html files.
I use underscore.js templates within my html files and they are usually wrapped within a script tag.
For example,
<script id="widget_template" type="text/template">
blah blah blah
</script>
Commit cc074c3 has broken that highlighting and I was wondering if there was perhaps a way I could fix it?
Cheers,
Xianyi
Code that looks like this and was properly formatted when typed (starting at column 1, then at column 7):
/*
* here I am
*/
/*
* here I am
*/
Looks like this if you highlight it and press =
:
/*
* here I am
*/
/*
* here I am
*/
Your proposed vim indent script doesn't indent correctly the following block:
var fs = require('fs'),
path = require('path');
Which it indent to:
var fs = require('fs'),
path = require('path');
In insert mode (cursor is _
):
/*
*
*/
_
Cursor ends indented by one character. Cursor should end on the original indent column (one character left, where the first / is).
A feature I would like in this syntax plugin would be to highlight both the parenthesis on function declaration and arguments individually.
See example here:
I have however managed to get parenthesis isolated outside of function declaration.
My edits to the syntax file are as follows: (probably a major hack, I am no expert in this)
amadeus@4c84029
Note, I would still like to keep arguments passed in on a function call separate from this.
Any help would be much appreciated.
The syntax file adjusts 'foldmethod'
and 'foldlevel'
, which is way out line with what a syntax file should be adjusting.
I realize the repo is merely vendoring a syntax file from a different maintainer, but I am reporting it here anyways because it's unfortunate I can't use such an awesome indenting algorithm without being subjected to such a huge regression.
Is there a way to replace the default parenthesis-aligned line continuation indenting with a regular 1-indent per continuation?
While the parenthesis-alignment may look nice occasionally, it makes the code very irregular, sharp, wastes a lot of space with longer function names, doesn't work with tabs and kills bunnies.
That is, instead of:
function(1,
2)
get
function(1,
2)
Type /
, *
, <CR>
, <CR>
, <CR>
, /
, and result is:
/*
*
*/
It seems good, but type /
, *
, *
, <CR>
, <CR>
, <CR>
, /
, and result is
/**
*
*/
It seems wrong.
Is the problem happen on only my vim?
Many jQuery plugins use 8 spaces instead of 2.
Is there any way to change an indent size using this plugin?
Its seems like a:
autocmd Filetype javascript setlocal ts=8 sts=8 sw=8
is being ignored since i use your plugin.
thanks
vim-javascript does currently not support micro templates. Those html templates are typically inside a <script type="text/html" id="my-tpl">
. Inside such a script tag we currently don't have any highlighting or indentation support.
I'm trying to follow the rules that JSLint has, and something like
var a=b,
c,
d;
gets indented as
var a=b,
c,
d;
which JSLint doesn't like.
I may also be doing something wrong of course.
The indentation is broken for any code proceeding a mutline var.
Here is an auto indented example:
function foo(d){
return d;
}
var x = 1,
b = 2;
function foo(d){
return d;
}
{
a: true,
b: false,
}
sometimes I have several longish arguments/expressions to a function call so I want to break the function call into something like (manually formatted):
fun( longish_argument,
some_expression() * 2.0 + x - 130.0,
nested_function_call( indent_me,
thanks ),
still_more_arguments);
the following is formatted with 'gg=G' with vim-javascript indenter:
/*
* the arguments below are short to make a more readable test case, but the
* point of this formatting is to be able to break function calls with long
* arguments...
*/
fun(1,
2,
3);
// doesn't return
fun(1,
2,
3
);
// doesn't either
fun(
1,
2,
3);
// again
fun(
1,
2,
3
);
// this is the only one working, but even it breaks in some contexts
switch(foo) {
case 1:
here(
1,
2, // why????
);
here(
1,
2,
3
); // seems recovered, but it's misindented
break;
case 2:
here(
1,
2
); // so it breaks after each case
break;
}
I'd be happy to help changing the indenter, but I'm lost in the script, could you explain the logic behind it?
Example:
methodCall(a,
b);
a = 1;
b = 2;
indent/javascript.vim:162
https://github.com/pangloss/vim-javascript/blob/master/indent/javascript.vim#L162
This should be lnum I believe, not line, as line hasn't been defined yet and throws a ton of errors - appears to work when I change line to lnum
If you type a /*
, then press enter, the *
to mark continuation is indented to match the /
, not the *
.
Desired behaviour:
/* some text<CR>
*
Actual behaviour:
/* some text<CR>
*
First, I want to say great job on this indent script, as it works great nearly all the time. I did encounter a bug with this particular data structure:
var data = {
arrayOfObjects: [
{
key: "value"
}
]
}
Notice that the key: "value" line and following brace are off by one indentation level.
Is it just me, or does the syntax highlighting included here not highlight curly and square braces?
The stock JS syntax file in Vim highlights the curly and square braces (but not normal parenthesis) fine - I figured this one would too!
Tested with both gVim and console vim with solarized and ir_black color schemes.
[120807 16:06:16] Bundle vim-javascript |~
[120807 16:06:16] $ git clone https://github.com/vim-scripts/vim-javascript.git|~
'/Users/reverbnation/.vim/bundle/vim-javascript' |~
[120807 16:06:16] > Cloning into '/Users/reverbnation/.vim/bundle/vim-javascrip|~
t'...^@fatal: https://github.com/vim-scripts/vim-javascript.git/info/refs not f|~
ound: did you run git update-server-info on the server?^@
I spent some time tracking down the specific change tonight that is impacting my indentation, and it looks like it was part of commit 2e97915 - specifically the change to s:syng_multiline
.
Here is an example of JS that demonstrates the broken indentation:
function test() {
// A comment
"some code";
}
If you put your cursor on the "some code";
line and hit O to start a new line above the code, and below the comment, you get an indent of 3 spaces, rather than the tab I would expect. This behavior is consistent when expandtab
is on or off, and my shiftwidth, tabstop, and softtabstop are all at 4. If I go to add code after the "some code";
line, everything is fine and the indent is okay.
Additionally, my default formatoptions
look to be croql
when I'm in a JS file, but even if I clear those out entirely so that there are no format options, I still see this behavior (and the removal of r
means you can reproduce it by being on the comment line and hitting o
to create a new line).
I would submit a pull request to fix this, but honestly I don't know enough about vimscript at this point to understand why it was changed to just comment\c
instead of the full JS comment pieces that are defined. I do see the notes on commit 2f39355 which explain that it's using more generic and shorter patterns, but at least for the comments, it seems to be introducing a problem, and I would politely request that the change for comments be reverted, unless someone better (such as @drslump who authored the original change) has any insights as to why the above example is breaking.
I've been hunting down what happened for a couple of weeks now and just learned about git bisect
, and so I was able to bisect it down to this commit, and then given that the commit was small, I tested undoing it line by line. It really is just this one line. Not sure why that would fail here.
Thank you kindly for your consideration! I hope this bug report is sufficient. :)
Indenting this works as expected
app = connect().
use(connect.favicon()).
use(connect.logger()).
use(connect.static(app.root + '/public')).
listen(app.port);
this doesn't.
app = connect()
.use(connect.favicon())
.use(connect.logger())
.use(connect.static(app.root + '/public'))
.listen(app.port);
Can someone point me in the right direction so I can fix it?
I ran into the same problem submitted by @artm in Issue #4, which was accidentally closed. I don't have permission to re-open the issue, so I've copy-n-pasted it below. Thanks!
sometimes I have several longish arguments/expressions to a function call so I want to break the function call into something like (manually formatted):
fun( longish_argument,
some_expression() * 2.0 + x - 130.0,
nested_function_call( indent_me,
thanks ),
still_more_arguments);
the following is formatted with 'gg=G' with vim-javascript indenter:
/*
* the arguments below are short to make a more readable test case, but the
* point of this formatting is to be able to break function calls with long
* arguments...
*/
fun(1,
2,
3);
// doesn't return
fun(1,
2,
3
);
// doesn't either
fun(
1,
2,
3);
// again
fun(
1,
2,
3
);
// this is the only one working, but even it breaks in some contexts
switch(foo) {
case 1:
here(
1,
2, // why????
);
here(
1,
2,
3
); // seems recovered, but it's misindented
break;
case 2:
here(
1,
2
); // so it breaks after each case
break;
}
I'd be happy to help changing the indenter, but I'm lost in the script, could you explain the logic behind it?
The following snippet causes syntax highlighting to be broken:
function foo(){
return /['"]/;
}
var s = 'asdf';
The quotes in the regular expression seem to be interpreted as the beginning of a string literal.
I noticed a couple indentation issues.
switch(test){
case 1:
alert('hi');
break;
case 2:
case 3:
default:
}
In this example break
isn't aligned with case, it seems only the first line gets indented properly. Also case 3
and default
get indented in when they should be all the same indent level.
var test = '\
hello world \
and goodbye \
\';
In this example, nothing gets indented. It would either be nice to indent one level or indent up to the quote (').
I don't know if I'm up to vim par to tackle these but definitely welcome them and am willing to test.
Hey, i've made some changes to the following line, haven't installed git yet, so i just made the change and hope that you will merge it in.
The case is as follows:
var y = a / b / c; // will identify / b / as regular expression, which is just wrong
I've modified it so that only this will be identified:
var y = / a /;
The relevant line change and comment is as follows:
"regexp, basically only regexp after '= *' will be matched, to prevent
"matching complex math expressions with multiple ''s. 'hs=e' will not
"highlight the '=', 'hs=e+1' will not highlight '= ', etc.
syntax region javaScriptRegexpString start=+= */\(\*\|/\)\@!+hs=e skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=javaScriptSpecial,@htmlPreproc oneline
Hello,
I really like this plugin, but I have thing that annoys me about it, which is that it ALWAYS sets a foldmethod. Wouldn't it be better to check if a foldmethod is already set, and if so not do anything?
Just my $0,02.
Thanks,
Chiel
Adding vim-javascript had a major performance impact on vim. Turning it off and removing it made the slowness in using vim go away. I can't be sure but I think it may even have led to vim crashing. The default vim support for JavaScript is not very good, but this is very slow at parsing large JavaScript files. I'm using an ivy-bridge Macbook Retina with SSD.
If you try to indent the following snippet you will get the 2nd line indented:
f('://'); e();
With that snippet, no problem:
function foo(one, two, three, four, five, six, seven, eight, night, ten) {
var syntax = "bug";
}
With the following one -> bug bug. The line is long, so I put a after the "ten" parameter (80-columns rule). The variable syntax
is not correctly indented :(
function foo(one, two, three, four, five, six, seven, eight, night, ten,
eleven, twelve) {
var syntax = "bug";
}
When the curly braces are on a new line, the indenting is wrong.
Expected result:
if (foo)
{
bar;
}
else
{
baz;
}
Actual result:
if (foo)
{
bar;
}
else
{
baz;
}
Got the following indent when using multiline comment in javascript
/*
*
*/
Expected intentation (After disable the vim-javascript bundle)
/*
*
*/
It's been two years, time for an update methinks?
When passing a function's arguments on multiple lines, the arguments are indented correctly but the line following the call keeps the extra indentation.
Actual:
$.get('',
{},
fn);
x = 1;
Expected:
$.get('',
{},
fn);
x = 1;
When opening a multiline /* comment block within an indented scope, the next line doesn't maintain the same indent level.
In insert mode (cursor denoted as _
):
function() {
function() {
/*_
}
}
Pressing <Enter>
now yields:
function() {
function() {
/*
* _
}
}
Instead, it should be:
function() {
function() {
/*
* _
}
}
Settings:
" vim:set sw=4 sts=4 ts=4 et:
I'm working through some backbone.js examples, and there's a chunk like:
var Target = Backbone.Model.extend({
promptColor: function() {
var cssColor = prompt("Please enter a CSS color:");
this.set({color: cssColor}); #problem line
}
});
But the line marked "problem line" de-indents when I type the closing curly to close off that hash, so it ends up as:
var Target = Backbone.Model.extend({
promptColor: function() {
var cssColor = prompt("Please enter a CSS color:");
this.set({color: cssColor}); #hey what am I doing back here?
}
});
I could break the hash up over several lines, and it does what you'd expect:
var Target = Backbone.Model.extend({
promptColor: function() {
var cssColor = prompt("Please enter a CSS color:");
this.set({
color: cssColor
});
}
});
But now I've got three lines of code instead of one.
if/else and for isn't highlighted.. is it just me or is it a bug?
thanks
Judging from the indent behaviour it seems the increment and decrement operators are treated like binary operators (or a binary operator followed by a unary operator).
For example,
a++
b
becomes
a++
b
I spent two minutes looking at the code and I believe s:continuation_regex and possibly also s:msl_regex should be altered so they do not match "++" and "--". I do not have a solution.
I create a picture
http://picasaweb.google.com/yaoweizhen/HxfMqJ?authkey=Gv1sRgCLi-5JL0m6rg3wE#5436915599151982914
Please look at the highlight brace. I haven't find perfect javascript indent extension of VIM.
Thanks
mikeyao
[email protected]
My knowledge of plugin development is limited but I've tried to work a solution out before posting this issue:
After digging around, I've discovered that Vim, by default, sources syntax/html.vim which, by default, sources syntax/javascript.vim when you edit a PHP document. This isn't actually a problem except for line 28 of syntax/javascript.vim: setlocal iskeyword+=$
This messes with my workflow when I'm coding as my muscle memory sees $ differently depending on whether I'm working on Javascript or PHP. I tried to figure out a way of fixing the issue and I think I got it to work. I removed setlocal iskeyword+=$
from syntax/javascript.vim and moved it to a new file ftplugin/javascript.vim based on a recommendation from freenode#vim.
This worked for me when I tested a JS file and a PHP file but when editing JS in an HTML file, it doesn't. While I don't tend to work with JS that is inline in HTML, I can understand that others may possibly want to. To work around this, I duplicated ftplugin/javascript.vim to ftplugin/html.vim and the functionality was restored when editing JS within HTML.
I do have a local clone with my changes applied that I can push to Github for you to check out and test; I don't know if it's too trivial for you to verify based upon my explanation above. When I get some spare time at the office, I can push it up and either leave a link here or just do a pull request.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.