Search code examples
windowsphpstormline-endings

PhpStorm saving with Linux line ending on Windows


Environment: Windows + PhpStorm

Issue: PhpStorm saves file with Windows line endings - and for shell script it's issue so there is need to always convert after copying to server.

Question: Is possible to configure PhpStorm to save file with Linux line endings - \n and not \n\r (new line + carriage return)?


Solution

  • You can safely use the \n line ending for .php and most of other files as well: PHP on Windows will read such files just fine.


    To set the default line ending for all new files: go to Settings/Preferences | Editor | Code Style and change Line separator option to the desired style (e.g. Unix and macOS (\n)).

    enter image description here


    To change line ending for a particular existing file: open the file and either change it via appropriate section in a Status Bar .. or via File | File Properties | Line Separators

    enter image description here

    enter image description here


    P.S.

    If you have EditorConfig plugin installed and enabled (it's a standard plugin now / bundled for quite a few years) then you can also configure this via .editorconfig file: this can be done on per file extension level so it's even more flexible than PhpStorm's own settings.

    As a bonus: this will also work in another editor/IDE that supports.editorconfig files.

    https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties#end_of_line