在多人開發專案時候,一定會遇到大家使用的編輯器大不相同 TextMate, Vim, Sublime Text 2, Geany, Notepad++…等,該如何統一程式碼的一致性呢?這邊要講得不是各種語言的 Coding Style,而是編輯器的設定,例如大家一定會遇到有的開發者使用 Tab 另外一群人使用 Space,在同一專案裡面就會發現有的 tab 有的 space,這樣看起來非常的亂,該如何統一大家的預設 indent style,就是要使用 EditorConfig 啦。使用方式很簡單,可以在專案目錄內加入 .editorconfig 內容設定如下
; EditorConfig is awesome: http://EditorConfig.org
root = true ; top-most EditorConfig file
; Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
; 4 space indentation
[*.py]
indent_style = space
indent_size = 4
; Tab indentation (no size specified)
[*.js]
indent_style = tab
; Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2
設定方式真的很簡單,如果是 Makefile 可以加入底下
[Makefile]
indent_style = tab
設定完成,最後只要裝上編輯器的 Plugin 即可,可以
參考這裡,目前支援編輯器如下
[Read More]