Can I set the VS Code default EOL based on file type?

EDIT : I was a bit "premature" with this answer. But it now works as of v1.40. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_40.md#fileseol-per-language


You can do this in vscode without an extension. You can make a language-specific setting:

In the command palette, search for "Configure language specific", select it and choose "shellscript" from the language options:

This will create the following in your settings:

"[shellscript]": {

},

Now add in whatever you want to apply to shellscript files only like (not all settings will work in there but most do):

"[shellscript]": {
    "files.eol": "\n"
},

VERY, VERY IMPORTANT:

The end-of-line sequence is used for new files. For existing files, the existing end-of-line sequence is always preserved. To change the end-of-line sequence for an existing file, use the Change End Of Line Sequence command.

  • from https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_40.md#fileseol-per-language

In your settings window, go to

Settings > Text Editor > Files > Eol option. You'll fine following available options there

- \n
- \r\n
- auto (default)

Here \n represents LF, \r\n represents CRLF, and auto use the operating system specific EL operator.

Select your option and save.

VS Code: version 1.13.3


You can use EditorConfig.

Install the editorconfig extension, and then add a .editorconfig file at the root of your project with this:

[*]
end_of_line = crlf

[*.{sh}]
end_of_line = lf

But as @axiac said, I would recommend to always use lf...