Question

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

Was it helpful?

Solution

Hope this article will help you:

How To Save a File from Visual C++ in UNIX Format

Unfortunately it seems to be the only way to save files in Unix format by default.

Personally I use Advance Save option in Save File dialog. But to be hones I never have a need to work with large number of files in Unix format from MSVS.

OTHER TIPS

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

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

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.

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.)

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);
}

Tools / Options / Text Editor / C# / IntelliSense change "Enter key behavior:" to "Always add new line on enter"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top