save text files with the newline convention present in the file when opened
The Visual Studio text file editor has an "advanced save" option that allows me to choose a particular format to save to, every time I save a file.
However, 99% of the time, the right thing to do is to save the file using whatever convention was present when the file was originally opened. Thus, if I open a file with LF-style line termination, new lines I add should be terminated with LF, and the file should be saved as LF-terminated. If I open a file with CRLF convention, new lines I *** should be terminated with CRLF, and it should be saved CRLF terminated. Repeat for each convention you want to support.
Currently, the text editor inserts CRLF for newlines, no matter what the convention in the file was when opened. This generates files with mixed-convention line endings, which is a terrible thing to work with.
Users should not have to know which convention is present in a file when opening, and then be forced to choose that convention when saving, to have the right thing happen. Users should also not have to choose a particular convention in a "convert to" menu before saving. Both of those options add significant, continuous, drag on workflow, and, being manual steps, cause errors to be made.
Visual Studio can detect the convention automatically, and can automatically do the right thing, and would be a much better text editor if it did.
New files can be created using whatever default you want (CRLF, for example) without user intervention. It's the insistence on inserting CRLF into files that are not loaded with CRLF endings that's the biggest sin.
We are currently evaluating whether we can include this feature in a future version of Visual Studio – thank you for your feedback!
Program Manager, Visual Studio Editor Team
Define an option to specify default globally for every file.
Stop inserting carriage returns into my files!
As of Visual Studio 2015 this is still an issue. Personally I would prefer a way to generally and globally set unix linefeeds as I don't see the reason to keep CR characters in this day and age (if disregarding notepad.exe)
Even better, copy IntelliJ IDEA: Allow setting EOL per-project (and optionally convert all of the project to the requested EOL).
If nothing else, using LF vs. CRLF can save a lot of space.
I've been using the Strip'em extension http://www.grebulon.com/software/stripem.php to "fix" this in VS2013 community edition (am about to try it with 2015, saddened to find this hasn't been added:/).
Could it be a global option or project persistent option to avoid choosing that option every time we save
li ning commented
Aslo, strings contain LF should be automatic convert to CR LF if the file was a CR LF file, vice versa. Because there is a very tricky bug in vs, at least 2012 have that: if a file have both LF and CR LF, the build result is incorrect! It will crash on by access violation!
Microsoft knows this. They aren't stupid. But they are a bit short sighted. As usual, they find little ways to make life difficult for developers targeting multiple platforms. And no, when I say multiple platforms, I don't mean multiple Windows platforms.
This (smart newlines) is a standard feature on -all- modern non-Microsoft IDE editors. There are no exceptions.
Paulo Renato Nascimento commented
This behavior is specially annoying when switching back and forth between Visual Studio and Xamarin Studio while developing Xamarin.iOS applications. Having a clever convention or even a project-wide setting would be a much welcomed feature, indeed.
Also, save in ascii by default if possible if the charcters in the file do not need unicode. This helps detect unintentially pasting in a non-ascii character into a source file. SQL Server manager's editor needed this for over 8 years starting with SQL Server 2005.