EditorConfig/vim: 如果单独在线则制表符丢失

EditorConfig/vim: tab character lost if alone on line

我正在使用具有这些设置的 vim plugin to EditorConfig

let g:EditorConfig_exclude_patterns = ['fugitive://.*']
let g:EditorConfig_core_mode = "external_command"
let g:EditorConfig_preserve_formatoptions = 1

我在 Ubuntu 上并安装了 EditorConfig:

sudo apt-get install editorconfig

我正在编辑一个开源项目中的源代码文件,其中包含如下行(“>”表示制表符):

// code
>
// code
>   
// code

我发现当我保存文件时,EditorConfig 会删除单独一行的制表符。

// code

// code

// code

项目的 .editorconfig 如下所示:

root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# npm is using 2 spaces when modifying package.json
[package.json]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

我查看了 EditorConfig 文档,但找不到保留杂散制表符的方法。

我知道这些杂散的制表符毫无意义,没有它们代码实际上更清晰,但我不想对我试图修补的文件进行额外的编辑。

还有其他人遇到过这个问题吗?

放弃

trim_trailing_whitespace = true

来自您的配置。 "Trailing" 并不一定意味着一行中的空格之前有实际字符;它还会影响全空白行。

仅申请某些项目/存储库

如果您需要对不同的目录进行不同的设置,您可以在 Vim 中使用 :autocmd 来改变选项值,或者使用成熟的 local vimrc插件。

我对EditorConfig了解不多,但是它的主页是这样写的:

When opening a file, EditorConfig plugins look for a file named .editorconfig in the directory of the opened file and in every parent directory.

因此,如果您需要为一个存储库进行不同的配置,只需将此类文件放入存储库的根目录,然后在那里重新配置 trim_trailing_whitespace 选项。