sublime text 軟件其實是自帶格式化插件的,但是它默認的格式化插件,不太好用,且沒有快捷鍵(雖然自己可以設置)。
其默認的格式化是在 Edit -> Line -> Reindent
為其設置快捷鍵,打開 Preference -> Key Bindings -user 寫入如下信息:
{ "keys": ["ctrl+alt+f"], "command": "reindent" }
自帶的格式化,就只會處理一下你的縮進問題,其他的一概不理。
下面要說的是格式化工具(HTML-CSS-JS Prettify),其快捷鍵是 Ctrl+Shift+H ,可以對html,css,js等進行格式化。
但是該插件需要node的支持,也就是說,你的機器沒有安裝node,則不可以使用這個插件。
該插件的配置文件在sublime安裝的所在目錄的,Data\Packages 文件夾下面,如下是我的安裝目錄:
D:\Program Files\Sublime Text 2\Data\Packages\HTML-CSS-JS Prettify
插件默認指定的node路徑是 “C:/Program Files/nodejs/node.exe”,如果你的node不是安裝在 "C:/Program Files/nodejs/",請更改配置文件的里面node的安裝路徑:
{ // Simply using `node` without specifying a path sometimes doesn't work :( // https://github.com/victorporof/Sublime-HTMLPrettify#oh-noez-command-not-found // http://nodejs.org/#download "node_path": { "windows": "D:/Program Files/nodejs/node.exe", "linux": "/usr/bin/nodejs", "osx": "/usr/local/bin/node" }, "format_on_save": false, "format_selection_only": true, "print_diagnostics": true }
現在一切都配置好了,趕緊去嘗試下該插件吧。