# editorconfig

# 1.了解


  • 【通配符】

    *                匹配除/之外的任意字符串
    **               匹配任意字符串
    ?                匹配任意单个字符
    [name]           匹配name中的任意一个单一字符
    [!name]          匹配不存在name中的任意一个单一字符
    {s1,s2,s3}       匹配给定的字符串中的任意一个(用逗号分隔) 
    {num1..num2}    匹配num1到num2之间的任意一个整数, 这里的num1和num2可以为正整数也可以为负整数
    
    1
    2
    3
    4
    5
    6
    7
  • 各个属性

    indent_style    设置缩进风格(tab是硬缩进,space为软缩进)
    indent_size     用一个整数定义的列数来设置缩进的宽度,如果indent_style为tab,则此属性默认为  tab_width
    tab_width       用一个整数来设置tab缩进的列数。默认是indent_size
    end_of_line     设置换行符,值为lf、cr和crlf
    charset         设置编码,值为latin1、utf-8、utf-8-bom、utf-16be和utf-16le,不建议使用utf-8-bom
    trim_trailing_whitespace  设为true表示会去除换行行首的任意空白字符。
    insert_final_newline      设为true表示使文件以一个空白行结尾
    root           表示是最顶层的配置文件,发现设为true时,才会停止查找.editorconfig文件    
    
    1
    2
    3
    4
    5
    6
    7
    8

# 2.使用


有些编辑器则需要安装editorConfig插件,如ATOM、Sublime、VS Code等

  • 项目目录创建 .editorconfig 文件

    $ touch .editorconfig
    
    1
  • .editorconfig 常用内容设置:

# editorconfig.org
root = true

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

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17