49

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)?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Jurosh
  • 6,984
  • 7
  • 40
  • 51

2 Answers2

93

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

LazyOne
  • 158,824
  • 45
  • 388
  • 391
0

In JetBrains IDEAs 2022.3.2, they've moved the format around; so you can find it under
Settings > Code Style > General > Line separator

enter image description here

Zach
  • 539
  • 1
  • 4
  • 22