Is there a way to always have LF line endings in Visual Studio? I can never seem to find it!
6 Answers
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
-
14IMHO, this should be the chosen answer to this posted. – sivabudh Jul 19 '10 at 22:50
-
@ShaChris23 - agreed; it's exactly what we need now. But the chosen answer was chosen 11 BEFORE Strip'em was even released. – nevelis Oct 04 '11 at 22:29
-
There is also a VS2010 version of it, so this is a good answer still. – CubanX Apr 26 '12 at 14:20
-
The upvoting system should ensure that this gets seen. – Adam Houldsworth Oct 03 '12 at 07:44
-
This addon is saving me much headachefulness in vs2012. – Stabledog Oct 18 '13 at 17:08
You don't have to install any plugins.
As mentioned here you can configure line endings in File -> Advanced Save options...
-
22What?! You mean I have to do that for every single file?! You don't consider this an answer, do you? – mbx Jul 07 '14 at 09:37
-
In VS 2008, this setting gets lost when you close and reopen VS even if you open the same solution again. – still_dreaming_1 Sep 30 '15 at 23:31
-
1Based upon the OP question, I don't think this is the solution they are looking for. – lordhog Oct 18 '16 at 19:22
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.

- 16,182
- 20
- 80
- 112

- 83
- 1
- 1
-
3Doesn't work for me. I already have that checked and it insists on saving files with CRLF (e.g. the .sln file). – Robin Green Apr 04 '14 at 08:59
-
4Consistent line endings is not the same as LF line endings. They can be consistently CRLF. – still_dreaming_1 Sep 30 '15 at 23:27
-
1"Consistent line endings on load" can help with existing files, but VS still seems to want to save new files with (consistent) CR-LF endings. – cjs Feb 06 '18 at 01:54
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.
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.)

- 49
- 1
- 6
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);
}

- 311
- 3
- 12
-
Where is this code supposed to go? Provides what might be a solution, but how to apply the solution is omitted. – lordhog Oct 18 '16 at 19:25
-
1Well, it would go somewhere you would invoke a SaveFileDialog. In Visual Studio, you would generally use the forms generator to create a button, for instance. This would result in a skeleton of a handler being added, and the function would be named something like: private: System::Void saveAsToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) – trindflo Nov 17 '16 at 15:54
-