Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Working with .sh files on Windows causes issues when running them in Linux Docker containers if they have EOL of CRLF. Can I make VS Code always work with LF for specific file type such as .sh while still using CRLF for all others?

I only find "files.eol": "\r\n" in settings, but this is global.

I understand you can change this in the bottom toolbar on a per-file basis, but I would like this to be the default for all .sh files.

like image 343
kspearrin Avatar asked Apr 24 '18 15:04

kspearrin


Video Answer


3 Answers

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...

like image 62
ChrisR Avatar answered Oct 10 '22 14:10

ChrisR


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

like image 19
Ariful Haque Avatar answered Oct 10 '22 15:10

Ariful Haque


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
like image 11
Mark Avatar answered Oct 10 '22 14:10

Mark