修复Sublime Text 2行结尾?

min*_*bit 174 line-endings sublimetext2

这是我的Settings - User配置:

{
    "auto_indent": true,
    "color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
    "default_line_ending": "LF",
    "detect_indentation": true,
    "font_size": 10.0,
    "ignored_packages":
    [
        "Vintage"
    ],
    "indent_to_bracket": false,
    "smart_indent": true,
    "tab_size": 4,
    "translate_tabs_to_spaces": true,
    "trim_automatic_white_space": true,
    "use_tab_stops": true
}
Run Code Online (Sandbox Code Playgroud)

default_line_ending选项的评论说: 对default_line_ending选项的评论

当我创建一个新文件时,我检查行结束在这里:

检查行结束

你可以看到它仍然是Windows ...任何想法?

Lei*_*igh 197

评论说

// Determines what character(s) are used to terminate each line in new files.
// Valid values are 'system' (whatever the OS uses), 'windows' (CRLF) and
// 'unix' (LF only).
Run Code Online (Sandbox Code Playgroud)

你在设置

"default_line_ending": "LF",

你应该设置

"default_line_ending": "unix",

  • 这只能手动完成,如果这是自动化的话会非常有用.您可以更改此信息,如上图 - > Line Endings-> Unix @soothsayer上图所示 (11认同)
  • 设置"default_line_ending":"unix",适用于新文件..但不适用于现有(较旧)文件.有谁知道如何改变这种行为? (10认同)
  • @soothsayer,对于现有文件,选择所有文本,然后选择`view` - >`line endings` - >`unix`.然后保存文档. (5认同)

小智 9

EditorConfig项目(Github的链接)是另一种非常可行的解决方案.类似于sftp-config.json和.sublime-project/workspace排序文件,一旦在项目文件夹或父文件夹中设置.editorconfig文件,每次在该目录结构中保存文件时,插件都将自动应用点文件中的设置,并为您自动执行一些不同的操作.其中一些是保存Unix样式的行结尾,添加文件结尾换行符,删除空格,以及调整缩进选项卡/空格设置.


快速示例

使用Package Control在Sublime中安装EditorConfig插件; 然后放置一个.editorconfig在父目录中命名的文件  (如果你愿意,甚至是你的家或根目录),其中包含以下内容:

[*]
end_of_line = lf
Run Code Online (Sandbox Code Playgroud)

而已.每当您在该目录结构中保存文件时,此设置将自动应用Unix样式的行结尾.你可以做更多很酷的事情,例如.修剪不需要的尾随空格或在每个文件的末尾添加尾随换行符.有关更多详细信息,请参阅https://github.com/sindresorhus/editorconfig-sublime上的示例文件,即:

# editorconfig.org
root = true

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

[*.md]
trim_trailing_whitespace = false
Run Code Online (Sandbox Code Playgroud)

root = true行意味着EditorConfig不会.editorconfig在目录结构的上层查找其他文件.