visual-studio 阻止 Visual Studio 在文件中混合行尾
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3994909/
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
Stop Visual Studio from mixing line endings in files
提问by Brett Ryan
When opening a text based file in Visual Studio 2010 it will then write my edits with CRLF instead of the line ending format of the original file. How can I stop VS from doing this? Any half decent editor should have this capability.
在 Visual Studio 2010 中打开基于文本的文件时,它将使用 CRLF 而不是原始文件的行尾格式编写我的编辑。我怎样才能阻止 VS 这样做?任何体面的编辑器都应该具有此功能。
What's worse is that since VS wrote the file with portions in CRLF, it then (when opening the file again) will present a dialog asking me to convert the files line ending.
更糟糕的是,由于 VS 使用 CRLF 中的部分编写了文件,因此(再次打开文件时)会出现一个对话框,要求我转换文件行尾。
回答by GvS
On the Filemenu, choose Advanced Save Options, you can control it there.
在File菜单上,选择Advanced Save Options,您可以在那里控制它。
Edit: Here's the documentation, you should have a file open first.
编辑:这是文档,您应该先打开一个文件。
回答by Johann Caron
In Visual Studio 2015 (this still holds in 2019 for the same value), check the setting:
在 Visual Studio 2015 中(这在 2019 年仍然保持相同的值),检查设置:
Tools > Options > Environment > Documents > Check for consistent line endings on load
工具 > 选项 > 环境 > 文档 > 检查加载时的行尾是否一致
VS2015 will now prompt you to convert line endings when you open a file where they are inconsistent, so all you need to do is open the files, select the desired option from the prompt and save them again.
VS2015 现在会在您打开不一致的文件时提示您转换行尾,因此您需要做的就是打开文件,从提示中选择所需的选项并再次保存。
回答by gearsin
With VS2010+ there is a plugin solution: Line Endings Unifier.
VS2010+ 有一个插件解决方案:Line Endings Unifier。
With the plugin installed you can right click files and folders in the solution explorer and invoke the menu item Unify Line Endings in this file
安装插件后,您可以右键单击解决方案资源管理器中的文件和文件夹并调用菜单项 Unify Line Endings in this file
Configuration for this is available via
对此的配置可通过
Tools -> Options -> Line Endings Unifier.
工具 -> 选项 -> 行尾统一符。
The default file extension list that is included is pretty narrow:
包含的默认文件扩展名列表非常狭窄:
.cpp; .c; .h; .hpp; .cs; .js; .vb; .txt;
Might want to use something like:
可能想要使用类似的东西:
.cpp; .c; .h; .hpp; .cs; .js; .vb; .txt; .scss; .coffee; .ts; .jsx; .markdown; .config
回答by Chris Schaller
see http://editorconfig.organd https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2017
请参阅http://editorconfig.org和https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2017
If it does not exist, add a new file called .editorconfig for your project
manipulate editor config to use your preferred behaviour.
如果它不存在,请为您的项目添加一个名为 .editorconfig 的新文件
操作编辑器配置以使用您的首选行为。
I prefer spaces over tabs, and CRLF for all code files.
Here's my .editorconfig
我更喜欢空格而不是制表符,所有代码文件都喜欢 CRLF。
这是我的 .editorconfig
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = crlf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
[*.tmpl.html]
indent_size = 4
[*.scss]
indent_size = 2

