Reputation: 2336
Is there a way to always have LF line endings in Visual Studio? I can never seem to find it!
Upvotes: 69
Views: 59828
Reputation: 349
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);
}
Upvotes: 0
Reputation: 49
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.)
Upvotes: 0
Reputation: 1844
You don't have to install any plugins.
As mentioned here you can configure line endings in File -> Advanced Save options...
Upvotes: 6
Reputation: 83
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.
Upvotes: 5
Reputation:
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
Upvotes: 72
Reputation:
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.
Upvotes: 1