CodeFormatter插件用来对代码进行格式化,使用方式,快捷键 ctrl+alt+f
codeformatter是Sublime Text 2 / 3的插件,支持格式(美化)源代码。
CodeFormatter支持的语言:
PHP - By phpfmt
JavaScript/JSON - By JSBeautifier
HTML - By Custom fork of BeautifulSoup
CSS - By JSBeautifier
SCSS - By Nishutosh Sharma
Python - By PythonTidy (only ST2)
Visual Basic/VBScript
Coldfusion/Railo/Lucee
下载方式:将Git源代码,clone到Sublime Text插件目录
Git地址:
https://github.com/akalongman/sublimetext-codeformatter
https://github.com/akalongman/sublimetext-codeformatter.git
PackageControl官网地址:
https://packagecontrol.io/packages/CodeFormatter
更多插件地址:
特别注意,对于HTML格式化的配置:
"codeformatter_html_options": { "syntaxes": "html,blade,asp,xml", // Syntax names which must process HTML formatter "format_on_save": true, // Format on save "formatter_version": "regexp", // Which formatter to use. Current options are "bs4" and "regexp". If an error occurs while loading the bs4 formatter, the regexp formatter will automatically be used "indent_size": 4, // indentation size "indent_char": " ", // Indentation character "indent_with_tabs": true, // Indent with one tab (overrides indent_size and indent_char options) "exception_on_tag_mismatch": false, // If the last closing tag is not at the same indentation level as the first opening tag, there's probably a tag mismatch in the file "expand_javascript": true, // (Under construction) Expand JavaScript inside of <script> tags (also affects CSS purely by coincidence) "expand_tags": true, // Expand tag attributes onto new lines "minimum_attribute_count": 2, // Minimum number of attributes needed before tag attributes are expanded to new lines "first_attribute_on_new_line": false, // Put all attributes on separate lines from the tag (only uses 1 indentation unit as opposed to lining all attributes up with the first) "reduce_empty_tags": true, // Put closing tags on same line as opening tag if there is no content between them "custom_singletons": "" // Custom singleton tags for various template languages outside of the HTML5 spec },
1. 格式化模式使用regexp比较理想
"formatter_version": "regexp",
2.启用保存时格式化,很不错
"format_on_save": true, // Format on save
更多插件: