AutoIndent for JavaScript in Vim that understands Semicolon Insertion

扶醉桌前 提交于 2019-12-21 14:33:26

问题


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 comment 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 comment here to dedent the else body
          var foo
          } else if (foo){
              var foo
              } // add a comment here to indent and break the following lines
              var foo
              })
              // all parenthesis match, but yet our indentations don't

回答1:


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
})


来源:https://stackoverflow.com/questions/2742441/autoindent-for-javascript-in-vim-that-understands-semicolon-insertion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!