關於代碼格式的美化,之前在win下一直用“alignment”這個插件,它能實現一鍵對齊和縮進。最近使用mac版的sublime text 2,不知道是什么原因,這個插件疑似失效…… 這對有潔癖的完美主義者簡直是沉重的打擊啊!
So,只能尋找其他的替代方法了。在package control的幫助下,找了幾個美化HTML代碼的插件,可惜效果都不盡如人意啊。天無絕人之路,借助強大的谷(bǎi)歌(dù),終於找到了解決方法,原文如下:
You don't need any plugins to do this. Just select all lines (CtrlA) and then from the menu select Edit → Line → Reindent. This will work if your file is saved with an extension that contains HTML like .html
or .php
.
If you do this often, you may find this key mapping useful:
{ "keys": ["ctrl+shift+r"], "command": "reindent" , "args": { "single_line": false } }
If your file is not saved (e.g. you just pasted in a snippet to a new window), you can manually set the language for indentation by selecting the menu View → Syntax → language of choice
before selecting the reindent option.
班門弄斧,幫大家翻譯一下:
你不需要使用任何插件就能解決這個問題。如果你已經把包含html代碼的文件之擴展名保存為.html或.php,只需全選所有行(Ctrl+A),然后從菜單選擇“Edit → Line → Reindent”,就好了。如果你經常用到,你可以找一下這個有用的按鍵映射:
{ "keys": ["ctrl+shift+r"], "command": "reindent" , "args": { "single_line": false } }
如果你的文件還沒保存(例如你剛把一段代碼粘貼到一個新窗口),在執行重新排版命令前,你可以通過點擊菜單“View → Syntax → 要選擇的語言”來設置想要縮進的語言。