visual-studio 将 Visual Studio 配置为使用 UNIX 行结尾

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3802406/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:30:25  来源:igfitidea点击:

Configure Visual Studio to use UNIX line endings

visual-studiovisual-studio-2005line-endingsend-of-line

提问by moala

We would like to use Visual Studio 2005 to work on a local copy of an SVN repository. This local copy has been checked out by Mac OS X (and updates and commits will only be made under Mac OS X, so no problem there), and as a consequence the line endings are UNIX-style.

我们想使用 Visual Studio 2005 处理 SVN 存储库的本地副本。这个本地副本已经被 Mac OS X 检出(并且更​​新和提交只会在 Mac OS X 下进行,所以没有问题),因此行尾是 UNIX 风格的。

We fear that Visual Studio will introduce Windows-style line endings. Is it possible to force Visual Studio to use UNIX line endings?

我们担心 Visual Studio 会引入 Windows 风格的行尾。是否可以强制 Visual Studio 使用 UNIX 行结尾?

采纳答案by Zero

As OP states "File > Advanced Save Options", select Unix Line Endings.

当 OP 指出“文件 > 高级保存选项”时,选择 Unix 行尾。

This will only affect new files that are created. Fixing any that were previously created can be done file-by-file or you can search for tools that will fix on-bulk.

这只会影响创建的新文件。修复之前创建的任何文件都可以逐个文件完成,或者您可以搜索将批量修复的工具。

回答by FragmentalStew

Here are some options available for Visual Studio Community 2017

以下是一些适用于 Visual Studio Community 2017 的选项

  1. "File > Advanced Save Options" has been removed by microsoft due to "uncommon use". Whatever that means. https://developercommunity.visualstudio.com/content/problem/8290/file-advanced-save-options-option-is-missed.htmlYou can add it back by going to "Tools>Customize", then "Commands" tab, select the drop down next to "Menu Bar" select "File" then "Add Command">File>Advanced Save Options..". You can then reorder it in the file menu by using "move down".
  1. 由于“不常用”,Microsoft 已删除“文件 > 高级保存选项”。不管它是什么意思。https://developercommunity.visualstudio.com/content/problem/8290/file-advanced-save-options-option-is-missed.html您可以通过转到“工具>自定义”,然后“命令”选项卡将其添加回来,选择“菜单栏”旁边的下拉菜单,选择“文件”,然后“添加命令”>“文件”>“高级保存选项...”。然后您可以使用“下移”在文件菜单中对其重新排序。

I don't know if you will have to then set the advanced save options for each and every file, but it might prevent the issue I was having where my Visual Studio kept adding CL RF line endings into my files that were uniformly LF.

我不知道您是否必须为每个文件设置高级保存选项,但它可能会阻止我遇到的问题,我的 Visual Studio 不断将 CL RF 行结尾添加到我的文件中,这些文件都是统一的 LF。

  1. But I took it one step further and I added an extension called "Line Endings Unifier" by going to "Tools>Extensions and Updates>Online" and then searching for "line endings" in the search bar to the right. I will use this to automatically force all of my scripts to save with uniform line endings of my choice, but you can do more with it. https://marketplace.visualstudio.com/items?itemName=JakubBielawa.LineEndingsUnifier

  2. strip'em is another solution that does something similar to Line Endings Unifier. http://www.grebulon.com/software/stripem.php

  1. 但我更进一步,通过转到“工具>扩展和更新>在线”,然后在右侧的搜索栏中搜索“行尾”,我添加了一个名为“行尾统一器”的扩展。我将使用它来自动强制我的所有脚本以我选择的统一行结尾进行保存,但您可以用它做更多的事情。 https://marketplace.visualstudio.com/items?itemName=JakubBielawa.LineEndingsUnifier

  2. strip'em 是另一种类似于 Line Endings Unifier 的解决方案。 http://www.grebulon.com/software/stripem.php

I am not sure how they differ or the advantages/disadvantages of either. I'm mainly using Line Endings Unifier just because it was in the Visual Studio Marketplace. I think I've used all of these methods in the past, but my memory is fuzzy.

我不确定它们有何不同或两者的优缺点。我主要使用 Line Endings Unifier 只是因为它在 Visual Studio Marketplace 中。我想我过去用过所有这些方法,但我的记忆很模糊。

回答by jcox

VS2017 supports .editorconfig files, which can be checked in along with your project. This is the relevant command for setting Unix line endings:

VS2017 支持.editorconfig 文件,可以与您的项目一起检入。这是用于设置 Unix 行结尾的相关命令:

end_of_line = lf

回答by GibboK

"File > Advanced Save Options", select Unix Line Endings works per file based.

“文件 > 高级保存选项”,选择 Unix Line Endings 作品基于每个文件。

Alternatively You can use Strip'em Add-in for Visual Studio

或者,您可以为 Visual Studio 使用 Strip'em 插件

This Add-in converts the text format of a file when it is saved in Visual Studio.

当文件保存在 Visual Studio 中时,此加载项会转换文件的文本格式。

More info here: http://www.grebulon.com/software/stripem.php

更多信息在这里:http: //www.grebulon.com/software/stripem.php

回答by kamayd

There are some VS extension that are useful to solve this problem I will recommend Trim line ends on save. This extension is free and open source. There are similar extensions that may work for you, just go to TOOLS | Extensions and Updates and search online for "line end"

有一些 VS 扩展对解决这个问题很有用,我会推荐Trim line ends on save。这个扩展是免费和开源的。有类似的扩展可能适合您,只需转到 TOOLS | 扩展和更新并在线搜索“行尾”

回答by Munther Jaber

enter image description hereThe LF is clickable and you choose either LF or CRLF.

在此处输入图片说明LF 是可点击的,您可以选择 LF 或 CRLF。

回答by ow3n

It is possible to force line endings in Visual Studio 2017 for Mac

可以在 Visual Studio 2017 for Mac 中强制换行

  1. Go to Tools > Add Custom Tool....
  2. In the dialog box that appears scroll the left menu down to the Text Editor section and select General.
  3. In the first option, Line ending conversion, change Leave line endings as isto Always convert line endings.
  1. 转到工具 > 添加自定义工具...。
  2. 在出现的对话框中,将左侧菜单向下滚动到“文本编辑器”部分,然后选择“常规”。
  3. 在第一个选项中,行结束转换,更改Leave line endings as isAlways convert line endings.

screenshot of dialog

对话框截图