这是我参与更文挑战的第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…