EditorConfig使用指南

EditorConfig是用于统一不同IDE编码风格配置的一种配置文件.

容易阅读,并且方便版本控制系统管理,默认支持EditorConfig的IDE有很多

具体规范可以查看下面两个网址

https://editorconfig-specification.readthedocs.io/

https://editorconfig.org/

示例

下面是一个官网的例子,使用的配置文件是ini格式

# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# unix格式换行符,并且在文件末尾插入新行
[*]
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

文件匹配

字符模式 匹配内容
* 匹配任意字母组成的字符串,除了路径分隔符/
** 匹配任意字母组成的字符串
? 匹配任意单个字符
[name] 匹配括号内的任意单个字符
[!name] 匹配除了括号内的字符
{s1,s2,s3} 匹配其中任何一个,用逗号隔开的 (Available since EditorConfig Core 0.11.0)
{num1..num2} 匹配两个数字之间的整数

支持的配置项

EditorConfig文件部分包含由等号(=)分隔的键值对。 除root外,所有键值对都必须位于生效的部分下。

注意大小写敏感

Key Supported values
indent_style 使用tab 还是 space
indent_size 设置缩进宽度
tab_width 设置制表符宽度, 默认和indent_size 值一样,通常不需要设定
end_of_line 设置换行符 lf, cr, or crlf
charset 设置字符编码 latin1, utf-8, utf-8-bom, utf-16be or utf-16le . Use of utf-8-bom is discouraged.
trim_trailing_whitespace 设置为 true 删除所有换行符前的空白字符false 不删除
insert_final_newline 设置true 保存的时候文件结尾会生成新行 and false 不生成新行
root 需要在开头指定,设定为true以后搜索editorconfig到当前的文件就会停止

下面是我个人的配置,如果在vscode下使用默认是不支持的,需要安装一个插件

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 当多人团队进行一个项目开发时,每个人可能喜欢的编辑器不同,有人喜欢Webstrom、有人喜欢sublime、还有人...
    长城_changcheng阅读 22,269评论 1 23
  • 很多新手在学习Python的时候,都会纠结Python该选择哪个解释器好,现在我就推荐PyCharm给大家: 1、...
    是小啊凡阅读 1,596评论 1 1
  • 有点懒得把图片传上来了,请移步这里看 Cocos官方论坛-wiki CocoaChina论坛帖子 上面两个是一样的...
    椒盐老蛏阅读 5,407评论 1 6
  • Eclipse设置空格和tab 勾选tab自动插入空格 设置profile 显示空格和tab 代码智能提示 Jav...
    liuliuzo阅读 847评论 0 0
  • Jackson使用规范以及代码示例 依赖包 Maven依赖: org.codehaus.jackson jacks...
    山石水寿阅读 4,776评论 0 3