Git Product home page Git Product logo

vim-javascript-syntax's Introduction

Enhanced JavaScript Syntax for Vim

Credits

  • Zhao Yi, Claudio Fleiner, Scott Shattuck (This file is based on their hard work)
  • gumnos (From the #vim IRC Channel in Freenode) (Who helped me figured out the crazy Vim Regexes)

Description

This file is a fork of this file and the stock one

This version of this file features the following text highlights:

  • Parenthesis, curly and regular brackets.
  • The semicolon or comma at the end of line.
  • Browser, DOM and "Ajax" keywords like objects, methods, properties and others.
  • Operation, comparison and logical symbols (=,==,===,!=,etc.).
  • Separate highlight of the arguments. Thanks to Billychan.

Rationale

While there are already a few syntax files in the wild (some even forks from this project), the goal is to have a syntax file that has current keywords for modern ES/JS development and to be fairly lean and quick on loading.

Screenshots

This is the stock Javascript syntax file

Solarized Light

Stock Vim JavaScript syntax file

This is with the Enhanced Syntax file Enhanced JavaScript Vim syntax

More screenshots here.

Hybrid

Stock Vim JavaScript syntax file

This is with the Enhanced Syntax file Enhanced JavaScript Vim syntax

Installation

  • Using Vim-Plug (Which I recommend), add this line to your .vimrc
Plug 'jelera/vim-javascript-syntax'
  • Using Vundle, add this line to your .vimrc
Plugin 'jelera/vim-javascript-syntax'
  • Using Pathogen, run this command in your shell
git clone https://github.com/jelera/vim-javascript-syntax.git ~/.vim/bundle/vim-javascript-syntax

Suggested Companion Plugins

  • Indentation The recommended way is to use Prettier and ALE.

It can be achieved with Javascript-Indent by Preston Koprivica. On my testing, it has proved to be the most capable and also indents HTML and JS inside HTML. The project is unmaintained for now, but you could fork it and improve upon it.

Contributions

While all contributions are always welcome, make sure your commit message follow this convention.

License

The same as Vim

vim-javascript-syntax's People

Contributors

averted avatar bgrohman avatar bigjason avatar billychan avatar bluekeys avatar boba1l0s2k9 avatar bvalosek avatar gabesoft avatar hendriklammers avatar jelera avatar jonhoo avatar julienw avatar juneidy avatar larsbs avatar magicdrive avatar mmwtsn avatar ohcibi avatar rachitnigam avatar romainbossart avatar sabakugaara avatar sleepycat avatar tlvince avatar tommcdo avatar watagashi avatar wilhelmtell avatar wpf500 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-javascript-syntax's Issues

JSDoc folds

Does this support folding on the description line of a JSDoc comment?

For example, I'd expect the following comment:

/**
 * Returns a random timestamp between 1900 and today's date.
 *
 * @return {int} A timestamp in Unix time format
 */

... to show the following when folded:

-- 5 lines: Returns a random timestamp between 1900 and today's date.

... whereas, it's currently displayed as:

-- 5 lines: *

Intendation on object methods

Not sure if this is a feature but if it is, I would love to be able to customize it.

Code inside functions is indented according to where the first letter of function is. This leads to a not constant indentation that depends on methods name.

var a = {
    b: function(){
           return;
       },
    hello: function(){
               return;
           }
}

Colors for function

javaScriptFuncKeyword is highlighting incorrectly when the same theme is compared with Atom and Sublime packages of the same themes.

Dracula theme

Code folding cancelled when touching code

Hey guys,

I am having problems with the code folding feature that apparently opens up all folded structures when editing the code. i.e: when creating a new function and typing the opening curly brace, all the remaining folds are then opened and I am required to re-close them with zx. The same happens with if statements when typing the closing curly brace.

As per the instructions shown on the README file, my ~/.vimrc file contains:

au FileType javascript call JavaScriptFold()

Here is a demo of the current behaviour:
vim-js-folding

If someone could point a workaround that it would be appreciated.
Thanks in advance

Incorrect precedence for regex and comment highlighting

If a line contains a slash and a comment, the plugin highlights the text from the slash to the comment as a regex, then fails to highlight the comment.

var result = 1 / 2; // this is a comment, but it won't be highlighted
var block = 2 / 3; /* this also will consider /3;/ as a regex */

Pathogen Nothing Happened

Hi. I installed via Pathogen, but I don't have any syntax hightlighting. Nothing happened...

Is there something else I need to do as well to get it to work??

Typescript?

Is there any way to configure this to also work with typescript?

Example of a file that completely screws up indentation

https://gist.github.com/3027255

Of course, it might be my coding that is at fault, but for some reason after a certain point it just makes EVERYTHING indented at the same level.

I've spent like an hour massaging where semicolons are, parens, and brackets, in an attempt to get the auto-indentation back (it was working perfectly till just a little while ago), but to no avail.

Error when adding '.' in a string

There is something wrong with following statements in javascript file, like this:

var url = 'http://www.google.com/';

'.google.com' is highlighted.

Parenthesis color mismatch

Note the parenthesis from define method and around foo parameter.

screenshot 2015-07-17 15 57 35

Apparently it's related to the function keyword. See below examples:

screenshot 2015-07-17 16 08 27

Folding support for alternatve function definition syntax

Code folding is supported for normal function definition syntax

function test() {

}

But code folding is not supported for the alternate function definition syntax

    test: function() {

    }

Would it be possible to add support for the second syntax style as well?

ES6 Arrow Notation

Creating a colour-scheme for your very in-depth syntax, really appreciate it. What I do miss is special syntax on arrow notation.

let foo = (key) => {};

In the above, => is coloured due to being operators (unless I'm mistaken), whereas key does not get the argument colouring that is defined under javaScriptFuncArg.

multiple functions defined in an object causes indentation to go wrong after the second one

#!/usr/bin/env node         
"use strict";               
module.exports = {          
  "a": function() {         

  },                        
  "b": function() {         

  },                        

};                          

When you enter a new entry, it adds an extra indent.

Verified that if i disable the plugin the indentation starts working normally again in this situation.

Also curious is that it requires two such functions, typing the "b" item does not cause erroneous indentation to occur. Note also the keys do not need to be in quotes to reproduce.

Adding $ to 'iskeyword' breaks PHP

Since PHP files can include JavaScript blocks, it seems that this plugin gets invoked for PHP files as well. This plugin runs setlocal iskeyword+=$, which is a good thing for JavaScript; however, in PHP, including $ in 'iskeyword' breaks the expected behaviour of the word text object, as well as things like * and #. In PHP, class members are declared like public $foo, but accessed like $this->foo, so technically $ is not part of the variable name, but more of a variable indicator.

I know this plugin is for JavaScript, but it's nice not to have unexpected side effects. I can't think of a perfect solution to this, unfortunately.

Wrong logic about function's end ')'

It's still some error about ')', this is my codes:

var http = require("http");
var url = require("url");

function start(route, handle) {

function onRequet(request, response) {
    var postData = "";
    var pathname = url.parse(request.url).pathname;
    var query = url.parse(request.url).query;
    console.log("Request for "+pathname+" received.");
    //console.log("Request query for "+query+" received.");

    request.setEncoding("utf8");

    //request.addListener("data", function(postDataChunk) {
        //postData += postDataChunk;
        //console.log("Received POST data chunk '"+
            //postDataChunk + "'.");
    // });
    var db = {
        users: [
        {name: 'tobi'},
        {name: 'loki'},
        {name: 'jane'}
        ]
    };

    console.log(db.users['tobi']);


    request.addListener("end", function() {
        route(handle, pathname, response, postData);
    });

    route(handle, pathname, response);

    response.writeHead(200, {"Contest-Type": "text/plain"});
    response.write("Hello World!!!");
    //response.write(content);
    response.end();
}

http.createServer(onRequet).listen(8888);

console.log("Server has started.");

}

exports.start = start;

You can see the part about line 19:
" // });"
");" is not comment, it's a bug
Uploading 2014-06-07--1402185594_251x165_scrot.png . . .

Object key overridden

Screenshot from 2019-08-05 06-58-38

How to reproduce:
Go to cursor object key than named as a url, error, title , href, target, ...
Go to command mode :echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
result: javaScriptHtmlElemProperties or javascriptDomElemAttrs, or javaScriptFetchAPIProperties ...

Object as function parameter with 2 spaces indentation

Indentation breaks when using 2 spaces for indentation.

To reproduce, first set this options:
:set tabstop=2 | set shiftwidth=2 | set softtabstop=2 | set expandtab

Then try this code and you should see that is indented as follows:

var foo = bar({
  a: 0,
    b:1
});

Setting indentation to 4 spaces fixes this.

Comment highlighting breaks on closing curly

Well, the problem is clearly seen from the screenshots below.

image

image

I couldn't find any strict recomentation for JS to break the line after the closing brace. JSHint doesn't generate any warnings too.

Add support for backslash-escaped multiline strings

All JS engines (as far as I know; tested in V8, SpiderMonkey, and JSC) support backslash-escaped multiline strings, but this still chokes on them. Really hoping for support, as it's hard to edit userscripts when your inlined CSS blows everything up.

Example of syntax:

var things = "this is a\
really long\
multiline string";

Dot triggers Special within strings

var foo = '<@m.message "someId">';

In this case I would expect everything within single quotes to be treated as a string, but message is shown with a different color and tagged as Special.

fold problem

I think the origin plugin from Yi Zhao works with fold. But now, the function for folding code disappear.
Will u add it back ?

Highlight arguments

Hi there,

Thanks for your work.
Would it be possible with Vim's syntax matching to highlight usages of a function's arguments? For example, to highlight usages (of accommodationId, startDate, endDate and userId) in a function like below:

  ...
  requestAvailability: function(accommodationId, startDate, endDate, userId) {
    var deferred = Q.defer();
    var request = {
      deferred: deferred,
      userId: userId,
      accommodationId: accommodationId,
      startDate: startDate,
      endDate: endDate
    };
    if (!userId) {
      UserService.getLoggedInUser().then(function(data) {
        request.userId = data.user.id;
        _makeOrDelayAvailabilityRequest(request);
      });
      return deferred.promise;
    }
    _makeOrDelayAvailabilityRequest(request);
    return deferred.promise;
  }
  ...

Sensible highlighting

I see this in just about all syntax files, but it really doesn't make any sense when you think about it.

Why do we highlight the actual 'function' keyword. Who gives a shit?

HiLink javaScriptFuncKeyword Function

Instead, why not highlight the function's name and identifier, which is far more likely to be the important bit that needs to stand out, not the literal word 'function'?

As far as I'm concerned it should be:

HiLink javaScriptFuncKeyword Noise

Thoughts?

DOM properties as JS object properties

Not sure if this is related to solarized or not, but when you create plain object properties that happen to also be DOM element properties, they're colored as such, which seems inconsistent. See tagName and className in the screenshot below.

screenshot

syntax group name for a variable name?

I apologize for the dumb question but what is the syntax group for a general variable name?
I want something like let myVar = 5; to have coloring on the myVar.

Plugin not workign

I installed this plugin using Pathogen as per instruction:

git clone https://github.com/jelera/vim-javascript-syntax.git ~/.vim/bundle/vim-javascript-syntax

Then included the following in my .virc file

au FileType javascript call JavaScriptFold()

After restarting vim and opening a JavaScript file I am not able to fold using the standard zo, zc commands .. any clue ?

Parenthesis color mismatch

same as #56 but more description,

I have the same issue, using
[email protected]:luochen1990/rainbow.git plugin at current latest hash: 18b7bc1 is:
to replicate I have a new file with a content:
[].map(function(a,b){ })
you will see the parenthesis has shifted color right after "b",
everything inside the curly braces is fine, except if you have another
function passed as a parameter

wrong fold with comment

Hi jelera, I found a strange behavior.
If my code like below:

function test() {
  // {}
  var val1;
}

The fold for the function will be wrong. You could reproduce it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.