_jsbeautify


Ⅰ. 插件描述

Modified base on jsbeautify.vim (move comma to head of ojbect's attribute line)

Ⅱ. 基本信息

创建日期:  2012-05-12
使用用户:  24
Github星:  1
插件作者:  will king

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin '/jsbeautify'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle '/jsbeautify'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug '/jsbeautify'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/vim-scripts/_jsbeautify

Ⅳ. 文档说明

Another plugin to format your JavaScript source code

I modified the jsbeautify.vim as I need. (Original jsbeautify.vim is here: http://www.vim.org/scripts/script.php?script_id=2727 ) (changes happened on lines 1, 4, 532, 534, 538, 540 and 503)


{
        a: 'a',
        b: 'b'
}

Move the comma after Object's attribute to next line's front.

{
        a: 'a'
        ,b: 'b'
}
 There won't be a newline after } , when it's in an Expression. Such as function({},{}).

 Example for these 2 changes mentioned above:
⇲
var p_roleMutexGroupListGrid, p_assignedMutexRoleGrid, p_unassignedMutexRoleGrid, p_roleDetailsForm;
var PID = pffp.setPID({}, {
        /若在維護中需要修改權限設置,請到全局配置文件中去修改。/
        roleMutexGroup_query: 101101
        ,roleMutexGroupMember_query: 101201
        ,roleMutexGroupMember_assign: 101202
        ,roleMutexGroupMember_remove: 101203
        ,roleMutexGroupMember_details: 101204
        ,role_details: 100805
});
$(function() {
        var array1 = [1, 2, 3];
        var array2 = [];
        for (var i = 0; i <= 3; i++) {
                array2.push(i);
        }
        if ({
                a: ''
                ,b: ''
                ,c: 2
        } === {
                b: ''
                ,c: 2
                ,a: ''
        } && ['', '', 1] == ['', '', 1]) {
                pffp.filterPermissionFunc({}, [PID.roleMutexGroup_query], [initRoleMutexGroupGrid])();//  There won be a newline after } , when it's in an Expression.
        }
});
var initRoleMutexGroupGrid = function() {
        p_roleMutexGroupListGrid = pffp.initGrid(null, {
                id: 'roleMutexGroupListGrid'
                ,confId: 'roleMutexGroupListGrid_conf'
                ,topBtn: true
                ,passParam: {}
        }, RMGGridRowClick); //  There won be a newline after } , when it's in an Expression.
}
⇱ END

This vim-script also works at a low performance:)  
vim-jsbeautify : Simple javascript formater base on js-beautify  http://www.vim.org/scripts/script.php?script_id=4017(this one looks like the one which can be faster, but I haven't try it. )

usage:
  <leader>_ff
or
  bind the g:_Jsbeautify() function to any short key you like.

Thanks jsbeautify.vim's author : aj3423          (as the name I know).
(I just a beginner, don't know how to write a complete vim-script file. )

添加新评论