Code Monkey home page Code Monkey logo

simple-javascript-indenter's Introduction

Simply Javascript Indenter

A simple vim indent plugin for javascript, support OOP, jquery

Install details

copy indent/javascript.vim to ~/.vim/indent

Options

  • g:SimpleJsIndenter_BriefMode (default 0)

    set 1 to turn brief mode on.

About Brief Mode

    Add 'let g:SimpleJsIndenter_BriefMode = 1' to ~/.vimrc to use brief mode.

    In Brief Mode script will not indent more than one shiftwidth each line.
    eg:
    For a lot of people prefer set shiftwidth to 4, so in normal mode, it will indent looks like
    each(function {
    ........something(); // indent 2 shiftwidth
    });
    (((
    ............something(); // indent 3 shiftwidth
    )));

    In brief mode it will indent as
    each(function {
    ....something(); // indent 1 shiftwidth
    });
    (((
    ....something();
    )))

    ATTENTION:
    Be sure to always close the brackets with the same level as open, or the after code will not indent correctly.
    eg:
    function() {
    ....each(function() {
    ....} // should use }); instead of }
    );    // already indented..
    something();
    }

About Indenting in switch {}

It's not a perfect indenting. see https://github.com/jiangmiao/simple-javascript-indenter/issues#issue/2

Indent Effects

    /*
    * Comment Test 
    * function() {
    */
    {
      /* a [{( */
      // b [{(
      comment('/* com', a /* [{( */); /* c */ // d
      ok();
      // Assign Test
      var a, /* { */
          b, // [
          c = '{'
      var a = "Hello" +
              "World"
      d = function() {
        aoeu
      }
      var k = function() {
        var k=3,
            m=4
      }

      var rurl = /{[('"/,
          r20 = /%20/g,

      a = 1,
      b = 2
      a = 1 +
          2 *
          3
    }

    // Function nested
    ;(function($) {
        $(document).ready(function() {
            $('#foo').click(function() {
                $.post(url, {
                    a: 1, 
                    b: 2,
                  }, function() {
                    ok(); 
                  }
                );
            });
        });
    })(jQuery);

    // Array Object Test
    string_test("('",'("',"[",'{',"\"{","\\'{"); 
    {
      array_object_test: [
        1,
        2,
        {
          a: [3,4],
          b: [
            3,
            4
          ],
          c: string_test("('",'("',"[",'{',"\"{","\\'{"),
          function_test: function() {
            return 0;
          },
          one_line_function_test: function() { return [1] }
        }
      ]
    }

    // One Line Test
    {
      if( a == b &&
        c == d ||
        e == f) 
      {
        ok();
      }
      if(a) {
        b;
      } else {
        e;
      }
      if(a)
        b;
      else if(k) {
        aeou
      } else
        c;
      while(true)
        foo += 1;
      try
        a;
      catch
        b;
      finally
        c;
      ok();
    }

simple-javascript-indenter's People

Contributors

jiangmiao avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.