visual-studio 如何在 Visual Studio (Express) 2008 中强制使用 unix (LF) 行结尾?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I force unix (LF) line endings in Visual Studio (Express) 2008?
提问by Chris Mayer
Is there a way to alwayshave LF line endings in Visual Studio? I can never seem to find it!
有没有办法在 Visual Studio 中始终使用 LF 行结尾?我似乎永远找不到它!
采纳答案by aku
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.
不幸的是,这似乎是默认情况下以 Unix 格式保存文件的唯一方法。
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.
我个人在“保存文件”对话框中使用“高级保存”选项。但说实话,我从来不需要处理来自 MSVS 的大量 Unix 格式的文件。
回答by
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
Visual Studio 2008 有一个加载项,可以在保存文件时转换行尾格式。你可以在这里下载:http: //grebulon.com/software/stripem.php
回答by renadeen
回答by user1955769
Yes, there is a way to always have LF line endings, at least in Visual Studio 2010 Pro.
是的,至少在 Visual Studio 2010 Pro 中,有一种方法可以始终使用 LF 行结尾。
Go to Tools | Options... | Environment | Documents
去 Tools | Options... | Environment | Documents
Then Enable the Check for consistent line endings on loadoption.
然后启用检查加载时行尾是否一致选项。
It works for me.
这个对我有用。
回答by user1955769
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.
解决方案关闭后,Visual Studio 2008 不会保留高级保存选项。如果这能让它始终如一地工作,我愿意手动编辑大量文件,但我不愿意每次打开 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.
这太糟糕了。由于 VS 确实支持将行结尾强制为后端所需的任何内容,因此它在 UI 中没有正确连接。也许微软会修复这是一个服务包。
回答by GLADIATORCOP
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.
VS 有一个名为 Strip'Em 的插件,您可以在其中选择要在保存时将所有行尾自动转换为哪种新行类型。
(You can choose between LF, CRLF, CR.)
(您可以在 LF、CRLF、CR 之间进行选择。)
回答by trindflo
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.
好像无意中找到了一个方法,发现这篇文章试图纠正它(我想要Windows CRLF EOL)!对我来说,执行以下操作会导致 UNIX(仅 LF)行结尾。
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);
}
回答by David Martin
Tools / Options / Text Editor / C# / IntelliSense change "Enter key behavior:" to "Always add new line on enter"
工具/选项/文本编辑器/C#/IntelliSense 将“输入键行为:”更改为“始终在输入时添加新行”

