Provide option to opt out of line ending normalisation for files
Upon saving a file edited with VS Code, it appears to perform line ending normalisation automatically and without user notification of any sort. Because of this, I've found myself bitten by large diffs in Git (I'm aware you can circumvent this using the -w flag) where a trivial fix to a single line of source code appears to affect a significant proportion of the file, which makes pull requests and reviews for such changes on GitHub a pain to sift through. Then again, I guess one could argue why a source file with mixed line endings should stay in version control like that anyway!
Visual Studio Community displays a prompt upon opening a file if it has mixed line endings and lets a user decide whether or not to have it fixed.

Version: 0.10.1
(By the way, great work on open sourcing VS Code too, thanks!)
The current file model normalizes the line endings as soon as the file is read (i.e. each line does not keep track of its EOL), the model only keeps track of one EOL for the entire file (which is computed on file open as the predominantely used EOL character).
@miqid Before we invest a lot into supporting this, when is it desirable to have a file with code that uses mixed EOL sequences? (i.e. why would you want to have a mixed EOL file at all)
Thanks for the insight @alexandrudima - a bit gutted to hear it won't be a trivial change.
Personally, I don't believe having mixed line endings around is a sane thing at all. Where the normalisation becomes a problem for me is when I need to make small edits in source files part of huge code repositories owned by people (usually in the commercial industry) who are extremely stringent on changes they allow through.
I've instead been using the Atom editor to commit changes to files where line endings aren't normalised as it preserves the original line endings of a while on save.
If it is going to be too much effort, I'm happy for the feature request to be closed off as there are alternatives beyond VS Code.
+1 to that!
This would be important when editing files with a binary payload. Think shellscripts with a built-in binary blob, or data files with a plaintext header part. For me, it would be OK if I could select a number of file extensions for which no conversions are ever applied.
Clearly, having mixed line endings in source code files is not sane at all. But this is something you often have to deal with in cross-platform development environments (Windows developers not aware at all of the EOL they are inserting in source code files, since the very beginning of the project). Having the possibility to choose or not EOL normalization would then be great for such scenarios.
Thanks
In my case, I would like to edit a .gitignore file with \n for line endings that contains an entry to ignore OSX Icon\r\r files. These are the only \r in the entire file and stripping them will break the file's behavior.
EOL normalization should be optional feature and off by default. We do not expect file editor will change non-edited code without user conscious.
Thanks
@gwax Icon? works for me
@shreyasminocha Yes, Icon? works when people are aware of the issue and remember to watch out for it. The risk is that a .gitignore file exists with a Icon\r\r entry and is edited by someone that does not know to watch out for line ending normalization.
That person comes along, adds an entry to the .gitignore, doesn't see the change from Icon\r\r\n to Icon\r\n or Icon\n, commits it and breaks the file for other people.
The crux of the issue is that the editor is making changes to the rest of the file without warning or explicit configuration request.
Compare to the behavior of the (similar) "Trim Trailing Whitespace". The feature also potentially edits untouched lines of a file but must be enabled by configuration before it will modify anything.
Is there a way to turn off this line ending normalization?
I've come across another scenario where the automatic normalisation of line endings is not desirable: an SQL export, which contains LF as the main line ending at the end of each row, but in my case also CRLF line endings within fields that contain multi-line text. I'm able to align these in my case, but I think this example shows that there are valid cases where line endings should not be automatically normalised.
I have the exact issue when making a pull request. I get surprised that the whole file is changed when I just changed one line! What makes it even worse, is that I only know that after I create the pull request and someone else review it !
I work on both Mac and Windows, and I believe switching between them is what makes this problem. Any way to disable this?
Please fix this issue since this is not just to be more comfortable, this is a mandatory feature of any modern editor:
how do you work with XML having CDATA entries with different lineendings than the surrounding XML document??
I just can't edit such a file in VSCode, since it will thrash the CDATA parts, or the XML part..... I guess I should stick to Notepad++.....
Please, there should be a mode like in Notepad++:
- VSCode try to guess the default line ending --> show CRLF / LF.
- The default is only used when typing ENTER key
- there is no other alteration of the file
- VSCode can display the true line endings character (realy this should be core feature, not an extension!), and show up with Toggle Controle Character (because they are, really)
- the user can choose to normalize the file OR normalize the selection
Completely agree with the above. This should be a core feature. I shouldn't have to install an extension to see the line endings either. I expected the show control characters feature to show line endings but it did not and I had to hunt for an extension.
I also would like to agree with the above statements. We for one develop on windows but then use linux docker containers. If we have to write shell scripts for docker using vscode, it usually causes issues. This is especially true if a developer tries to just modify one line, they have to be aware and make sure they set the line ending back to LF.
ooh, Can't believe this still isn't fixed!
Will this option help to see the difference in line endings in the "diff" window as well? Currently that window does not visualize the difference in line endings.
The use case is like the following: I run "d2u <filename>" in bash terminal thus changing the CRLFs to LFs. Then I open diff through "Changes" in the "Source Control" Activity Bar item. The diff window does not visualize the difference, The screenshot is attached.

I have to agree, this is undesired behavior, you should make it possible to turn of this normalization , keep it on by default, but give us an option, please.
I agree, this is the kind of "automatic cleverness" that gives modern technology a bad name. VSCODE is a great IDE but must resist temptation to get over-complicated. Programmers need to be in control; they need to know about line-ending issues. We use unix line-endings on text files across the board, whether developer is running on Windows, Mac or Linux. We just use editors that work with unix line endings. Please fix this with great urgency. Thanks