Vim Javascript 缩进插件: Simple Javascript Indenter v1.4.1

名称: Simple Javascript indenter
类别: Javascript Indent
版本: v1.4.1
作者: JiangMiao
更新: 2011-04-23
兼容: vim 7.0+
下载地址:
Github: http://github.com/JiangMiao/simple-javascript-indenter
Vim: http://www.vim.org/scripts/script.php?script_id=3227

描述
支持任意多层函数嵌套的vim缩进插件, 特别适合 Jquery之类的库。


安装:
复制 indent/javascript.vim 到 ~/.vim/indent

关于 Brief Mode
添加 let g:SimpleJsIndenter_BriefMode = 1 到 ~/.vimrc 开启brief 模式。
在Brief Mode下,每行的缩进不超过1
如: 普通缩进模式
each(function {
........something(); // indent 2 shiftwidth
});
(((
............something(); // indent 3 shiftwidth
)));

Brief Mode:
each(function {
....something(); // indent 1 shiftwidth
});
(((
....something();
)))

注意事项:
括号打开与关闭的方式应该一致
eg:
function() {
....each(function() {
....} // 应该使用 }); 而不应 } 与 );分2行。
); // 已经缩进过了。。
something();
}

缩进效果:


更新历史
2011-04-23 Version 1.4.1
Update: Indent current line when input } ) ]
See https://github.com/jiangmiao/simple-javascript-indenter/issues/4

Update: Change comment indentation style
See https://github.com/jiangmiao/simple-javascript-indenter/issues/5

2011-03-26 Version 1.4.0
New: Support switch case indenting.

2011-03-22 Version 1.3.4
Fix: failed indent for
function escapeattr(b) {
return b ? b.replace(/([\.#\[\]])/ig, "\\$1") : ""
}

https://github.com/jiangmiao/simple-javascript-indenter/issues#issue/1 (Thanks to whentp)

2010-01-08 Version 1.3.3
修正了1个JS格式,具体见ChangeLog

2010-01-07 Version 1.3.2
修正了1个JS格式,具体见ChangeLog

2010-11-22 Version 1.3.1
修正了3个JS格式,具体见ChangeLog

2010-09-23 Version 1.3.0
支持Brief模式

2010-09-08 Version 1.2.1
NEW: 支持无括号的if else while try catch finally else if

2010-09-06 Version 1.1.0
NEW: 支持赋值语句的缩进
共8条评论
  1. shepherdwind @ 2010-09-23 16:13:54 回复

    很不错,使用有了一下,只是不知如何调节每个tab的空格数.是indent.vim控制的还是全局设置的啊?
    如果能加一些注释就更好了

    • JiangMiao @ 2010-09-23 18:02:19

      tab宽度设置可通过修改e $MYVIMRC ($MYVIMRC一般会指向~/.vimrc)
      set ts (tabstop) tab的宽度
      set sts (softtabstop) 按下tab或backspace后的缩进距离
      set sw (shiftwidth) 缩进的宽度
      比如 set ts=2 sw=2 sts=2 expandtab “设为宽度为2的且展开为空格的tab模式

  2. Jichao @ 2010-10-03 21:14:39 回复

    缩进效果的那张图片完全看不清楚,另谢谢分享.

    • JiangMiao @ 2010-10-04 22:53:51

      点击可放大,放大后我这里看得挺清楚。

  3. Jichao @ 2010-10-03 21:18:48 回复

    还有确实能够正常处理jQuery非常之感谢.

  4. alswl @ 2011-09-15 11:40:50 回复

    请教一个问题,我在使用gg=G时候,会把所有代码缩进改为0,是不是我的vimrc设置有问题?

    • JiangMiao @ 2011-09-15 23:40:52

      先查看.vimrc中是否有
      set autoindent ruler 启用自动缩进
      filetype plugin indent on 允许载入indent插件
      再set 查看下syntax与shiftwidth的值,syntax应为javascript shiftwidth为2, 4, 8等
      再执行echo TrimLine(‘”aaa”‘)输出是否为_(下划线),如果没有下划线输出,表示插件未在使用中。

发表评论

电子邮件地址不会被公开。 必填项已被标记为 *

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>