最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

AutoIndent for JavaScript in Vim that understands Semicolon Insertion - Stack Overflow

programmeradmin3浏览0评论

I don't end my JavaScript statements with semicolons when newlines will work. No flames, please. My question is, is there an automatic indentation package for vim that will work?

Here is an example of how dumb it is:

$(function(){
    var foo // code starts here,
    // The following line breaks things, but adding a ment to it fixes things
({a:1})
var foo // everything is stuck left now.
          ({a:1})
          var foo // previous line justifies all following lines wherever you put it

          function flat(){
              var foo // function starts out right, but the next line dedents it
          ({a:1})
          var foo
      }
      var foo // now we're over here
      if (foo) {
          var foo // this if block doesn't close properly
          } else if (foo){ // add a ment here to dedent the else body
          var foo
          } else if (foo){
              var foo
              } // add a ment here to indent and break the following lines
              var foo
              })
              // all parenthesis match, but yet our indentations don't

I don't end my JavaScript statements with semicolons when newlines will work. No flames, please. My question is, is there an automatic indentation package for vim that will work?

Here is an example of how dumb it is:

$(function(){
    var foo // code starts here,
    // The following line breaks things, but adding a ment to it fixes things
({a:1})
var foo // everything is stuck left now.
          ({a:1})
          var foo // previous line justifies all following lines wherever you put it

          function flat(){
              var foo // function starts out right, but the next line dedents it
          ({a:1})
          var foo
      }
      var foo // now we're over here
      if (foo) {
          var foo // this if block doesn't close properly
          } else if (foo){ // add a ment here to dedent the else body
          var foo
          } else if (foo){
              var foo
              } // add a ment here to indent and break the following lines
              var foo
              })
              // all parenthesis match, but yet our indentations don't
Share Improve this question edited Apr 30, 2010 at 6:30 Nick Retallack asked Apr 30, 2010 at 5:23 Nick RetallackNick Retallack 19.6k19 gold badges94 silver badges116 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

I'm happy with the following Vim Script:

  • Improved Javascript Indent script for Vim

Result of your code after a gg=G:

var one = 1
var two = 2
var fun = function(){
  var three = 3
  var four = 4
  var five = 5
}

var fun2 = (function(foo){
  var six = 6
})
发布评论

评论列表(0)

  1. 暂无评论