這是我參與更文挑戰的第3天,活動詳情查看:更文挑戰git
之前寫的文章,繼續分享。github
顧名思義,EditorConfig就是編輯器配置,幫助開發人員在不一樣的編輯器和IDE之間定義和維護一致的編碼樣式,由用於定義編碼樣式的文件格式和一組文本編輯器插件組成,這些插件使編輯器可以讀取文件格式並遵循定義的樣式。EditorConfig文件易於閱讀,而且與版本控制系統配合使用。json
下面是一個.editorconfig文件的示例,爲Python和Javascript文件設置了行尾以及縮進的樣式。markdown
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8
# 4 space indentation
[*.py]
indent_style = space
indent_size = 4
# Tab indentation (no size specified)
[Makefile]
indent_style = tab
# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2
# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
複製代碼
當用IDE打開一個文件時,EditorConfig插件會在打開文件的目錄和其每一級父節點查找.editorconfig文件,直到找到一個配置了root = true的配置文件。編輯器
EditorConfig文件使用INI格式。斜槓(/)做爲路徑分隔符,#或者;做爲註釋。路徑支持通配符:ide
通配符 | 說明 |
---|---|
* | 匹配除/以外的任意字符 |
** | 匹配任意字符串 |
? | 匹配任意單個字符 |
[name] | 匹配name字符 |
[!name] | 不匹配name字符 |
[s1,s2,s3] | 匹配給定的字符串 |
[num1..num2] | 匹配num1到mun2直接的整數 |
EditorConfig支持如下屬性:工具
屬性 | 說明 |
---|---|
indent_style | 縮進使用tab或者space |
indent_size | 縮進爲space時,縮進的字符數 |
tab_width | 縮進爲tab時,縮進的寬度 |
end_of_line | 換行符的類型。lf, cr, crlf三種 |
charset | 文件的charset。有如下幾種類型:latin1, utf-8, utf-8-bom, utf-16be, utf-16le |
trim_trailing_whitespace | 是否將行尾空格自動刪除 |
insert_final_newline | 是否使文件以一個空白行結尾 |
root | 代表是最頂層的配置文件,發現設爲true時,纔會中止查找.editorconfig文件 |
這些編輯器捆綁了對EditorConfig的原生支持。 oop
要將EditorConfig與其中一個編輯器一塊兒使用,須要安裝一個插件。 post
要將EditorConfig與其中一個無頭工具一塊兒使用,也須要安裝一個插件。 編碼
# http://editorconfig.org
root = true
[*]
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
複製代碼
# editorconfig.org
root = true
[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
複製代碼
官網:editorconfig.org/ wiki文檔:github.com/editorconfi…