这是我的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
}
对default_line_ending
选项的评论说:
当我创建一个新文件时,我检查这里的行结束:
你可以看到它仍然是Windows ...任何想法?
评论说
// 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).
你在设置
"default_line_ending": "LF",
你应该设置
"default_line_ending": "unix",
EditorConfig project(Github link)是另一种非常可行的解决方案。类似于sftp-config.json和.sublime-project / workspace排序文件,一旦在项目文件夹或父文件夹中设置.editorconfig文件,每次在该目录结构中保存文件时,插件都将自动应用点文件中的设置,并为您自动执行一些不同的操作。其中一些是保存Unix样式的行结尾,添加文件结尾换行符,删除空格,以及调整缩进选项卡/空格设置。
使用Package Control在Sublime中安装EditorConfig插件;然后将名为.editorconfig
的文件放在父目录(如果您愿意,甚至是您的主页或根目录)中,其中包含以下内容:
[*]
end_of_line = lf
而已。每当您在该目录结构中保存文件时,此设置将自动应用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
root = true
行意味着EditorConfig不会在目录结构的上层查找其他.editorconfig
文件。
将行结尾从LF更改为CRLF:
打开Sublime并按照以下步骤操作: -
1按Ctrl + Shift + p然后安装包名称行统一结尾
然后再按Ctrl + shift + p
2在空白输入框中输入“Line unify ending”
3点按两次输入
Sublime有时可能会冻结,因此会将行结尾从LF更改为CRLF
一次修改项目的所有文件(批处理)的最简单方法是通过Line Endings Unify包:
{
"keys": ["ctrl+alt+l"],
"command": "line_endings_unify"
},
在Preferences - > KeyBindings +按Ctrl + Alt + L的用户数组(右窗格,打开[
之后)。如another answer中所述:
- 回车符(CR)字符(
0x0D
,\r
)[...]早期的Macintosh操作系统(OS-9及更早版本)。- 换行(LF)字符(
0x0A
,\n
)[...]基于UNIX的系统(Linux,Mac OSX)- 行尾(EOL)序列(
0x0D 0x0A
,\r\n
)[...](非Unix:Windows,Symbian OS)。
如果您有node_modules,build或其他自动生成的文件夹,请在运行包之前将其删除。
运行包时:
js,jsx
)。\n
。