Sublime Text 2 css js代码格式化插件css format , jsformat

2015-12-16

由于HTML-CSS-JS Prettify插件有关nodejs路径问题导致插件不能用,所以转入css format , jsformat,安装前确保已上网及已安装Package Control  ( Package Control 安装教程)。

  1. CSS Format 介绍


 保存时自动格式化

打开 Preferences > Package Settings > CSS Format > Settings – Default,将 Settings – Default 里的内容复制到 Preferences > Package Settings > CSS Format > Settings – User 中,然后将 format_on_save 的值改为 true。

注意:你需要始终编辑 Settings – User 文件,不要编辑 Settings – Default 文件,否则下次插件更新会覆盖你的设置。

    2. jsformat(配置

默认配置格式化后间隙太大,需要将配置文件( Preferences > Package Settings > jsFormat > Settings – User 中)新增以下内容 

{

    // exposed jsbeautifier options

    "translate_tabs_to_spaces": true,

    "tab_size": 4,

    "indent_with_tabs": false,

    "preserve_newlines": true,

    "max_preserve_newlines": 4,

    "space_in_paren": false,

    "jslint_happy": true,

    "brace_style": "end-expand",

    "keep_array_indentation": false,

    "keep_function_indentation": false,

    "eval_code": false,

    "unescape_strings": false,

    "break_chained_methods": false,

    "e4x": false,

    "wrap_line_length": 0,


    // jsformat options

    "format_on_save": true,

    "jsbeautifyrc_files": false

}


    3.Sublime Text 2自带代码格式化工具


选中代码

菜单-edit-line-reindent 完成