Vim中JavaScript的AutoIndent可以理解分号插入 [英] AutoIndent for JavaScript in Vim that understands Semicolon Insertion

查看:83
本文介绍了Vim中JavaScript的AutoIndent可以理解分号插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当换行符可用时,我不会以分号结束我的JavaScript语句.请不要起火.我的问题是,是否有适用于vim的自动缩进程序包可以工作?

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?

这是一个愚蠢的例子:

$(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

推荐答案

我对以下Vim脚本感到满意:

I'm happy with the following Vim Script:

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

这篇关于Vim中JavaScript的AutoIndent可以理解分号插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆