如何在 Visual Studio (Express) 2008 中强制使用 Unix (LF) 行结尾?
-
09-06-2019 - |
题
有没有办法 总是 Visual Studio 中有 LF 行结尾吗?我似乎永远找不到它!
解决方案
希望这篇文章能够帮助您:
如何将 Visual C++ 中的文件保存为 UNIX 格式
不幸的是,这似乎是默认情况下以 Unix 格式保存文件的唯一方法。
我个人使用“保存文件”对话框中的“高级保存”选项。但说实话,我从来不需要从 MSVS 处理大量 Unix 格式的文件。
其他提示
Visual Studio 2008 有一个加载项,可以在保存文件时转换行尾格式。你可以在这里下载: http://grebulon.com/software/stripem.php
您不必安装任何插件。如上所述 这里 您可以配置行结尾 File -> Advanced Save options...
是的,有一种方法可以始终使用 LF 行结尾,至少在 Visual Studio 2010 Pro 中是这样。
去 Tools | Options... | Environment | Documents
然后启用 检查加载时行尾是否一致 选项。
这个对我有用。
关闭解决方案后,Visual Studio 2008 不会保留高级保存选项。我愿意手动编辑大量文件,如果这样可以使其工作一致,但我不愿意每次打开 VS 时都更改所有设置。
这太糟糕了。由于 VS 确实支持将行结尾强制为后端所需的任何内容,因此它只是在 UI 中没有正确连接。也许微软会通过一个服务包来解决这个问题。
VS 有一个名为 Strip'Em 的插件,您可以在其中选择保存时将所有行结尾自动转换为哪种新线型。
(您可以在 LF、CRLF、CR 之间进行选择。)
我似乎偶然发现了一个方法,并发现这篇文章试图纠正它(我想要 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);
}
工具 /选项 /文本编辑器 / C# / Intellisense更改“输入密钥行为:”“始终在Enter上添加新行”