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

前端 未结 3 1451
执念已碎
执念已碎 2021-01-18 07:19

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 fo

相关标签:
3条回答
  • 2021-01-18 07:41

    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
    0 讨论(0)
  • 2021-01-18 07:43

    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

    0 讨论(0)
  • 2021-01-18 07:54

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

    0 讨论(0)
提交回复
热议问题