Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 956
Jurosh Avatar asked Nov 07 '16 17:11

Jurosh


People also ask

What is line ending in Windows?

Text files created on DOS/Windows machines have different line endings than files created on Unix/Linux. DOS uses carriage return and line feed ("\r\n") as a line ending, which Unix uses just line feed ("\n").

What are Linux line endings?

Back to line endings The reasons don't matter: Windows chose the CR/LF model, while Linux uses the \n model. So, when you create a file on one system and use it on the other, hilarity ensues.

What is a line separator?

The line separator used by the in-memory representation of file contents is always the newline character. When a file is being loaded, the line separator used in the file on disk is stored in a per-buffer property, and all line-endings are converted to newline characters for the in-memory representation.


1 Answers

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


To set default line ending for all new files: go to Settings/Preferences | Editor | Code Style and change Line separator (for new files) option to the desired style (e.g. Unix and OS X (\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 Status Bar .. or via File | File Properties | Line Separators

enter image description here

enter image description here


P.S.

If you do have EditorConfig plugin installed and enabled ... you might also configure this via .editorconfig file -- there you may specify what line ending to use (this can be done on per file extension level .. so it's more flexible than PhpStorm's own setting).

This will also work in another editor/IDE that supports such file.

like image 168
LazyOne Avatar answered Sep 25 '22 13:09

LazyOne