How do I force unix (LF) line endings in Visual Studio (Express) 2008?

Visual StudioVisual Studio-2008FormattingEditorLine Endings

Visual Studio Problem Overview


Is there a way to always have LF line endings in Visual Studio? I can never seem to find it!

Visual Studio Solutions


Solution 1 - Visual Studio

There'a an add-in for Visual Studio 2008 that converts the end of line format when a file is saved. You can download it here: http://grebulon.com/software/stripem.php

Solution 2 - Visual Studio

You don't have to install any plugins. As mentioned here you can configure line endings in File -> Advanced Save options...

Solution 3 - Visual Studio

Yes, there is a way to always have LF line endings, at least in Visual Studio 2010 Pro.

Go to Tools | Options... | Environment | Documents

Then Enable the Check for consistent line endings on load option.

It works for me.

Solution 4 - Visual Studio

Visual Studio 2008 doesn't retain the advanced save options after the solution is closed. I would be willing to hand edit a lot of files if that would make it work consistently, but I am not willing to change all of the settings every time I open VS.

This is too bad. Since VS does support forcing the line-endings to whatever is desired in the backend, its just not hooked up properly in the UI. Maybe Microsoft will fix this isn a service pack.

Solution 5 - Visual Studio

There's a plugin to VS called Strip'Em where you can choose which kind of new line type you want to auto convert all the line endings to when saving.

(You can choose between LF, CRLF, CR.)

Solution 6 - Visual Studio

I seem to have found a method by accident and found this article attempting to correct it (I want Windows CRLF EOL)! Doing the following results in UNIX (LF only) line endings for me.

SaveFileDialog^ dialog = gcnew SaveFileDialog();
System::Windows::Forms::DialogResult DR;
dialog->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
dialog->FilterIndex = 2;
dialog->RestoreDirectory = true;
dialog->DefaultExt = "txt";
DR = dialog->ShowDialog(this);
if ( DR == System::Windows::Forms::DialogResult::OK )
{
	// Get the page (tab) we are currently on
	System::Windows::Forms::TabPage ^selPage = this->tabControl1->SelectedTab;

	// Note: technically the correct way to look for our control is to use Find and search by name
	// System::Windows::Forms::RichTextBox ^selText = selPage->Controls->Find("rtb", false);
	// I only add one control (rich text) so first control ([0]) must be it
	System::Windows::Forms::RichTextBox ^selText = safe_cast<System::Windows::Forms::RichTextBox^>(selPage->Controls[0]);

	// Just let a Windows forms method do all the work
	File::WriteAllText(dialog->FileName, selText->Text);
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChris MayerView Question on Stackoverflow
Solution 1 - Visual StudiogrebulonView Answer on Stackoverflow
Solution 2 - Visual StudiorenadeenView Answer on Stackoverflow
Solution 3 - Visual Studiouser1955769View Answer on Stackoverflow
Solution 4 - Visual StudioEdward ReusserView Answer on Stackoverflow
Solution 5 - Visual StudioGLADIATORCOPView Answer on Stackoverflow
Solution 6 - Visual StudiotrindfloView Answer on Stackoverflow