1

It is possible to set the line endings for a file. This converts existing line endings, and works when adding a manual line break. However, it does not seem to insert the correct line endings when formatting a document or when auto-formatting is triggered (for example when adding a closing brace }).

I have tried the .editorconfig file, which works for things like spaces vs. tabs, but doesn't solve the formatting line ending issue either.

Did anyone succeed at this? Or is the only way to use a Visual Studio extension?

Related questions:

Selmar
  • 722
  • 1
  • 5
  • 12
  • 3
    Report this through VS Feedback and specify which language is doing this. Formatting in Visual Studio is done by each language separately, so whichever language you are using is likely not respecting your settings. – Jimmy Feb 02 '23 at 17:52
  • Have seen this myself. Formatting a document doesn't respect the editorconfig file which is a shame. @Selmar please update the question if you opened up an item through VS Feedback. – Baklap4 Feb 27 '23 at 13:33

1 Answers1

3

Like the comments saids its dependant on the language. Just a suggestion but VS supports editorconfig;

https://editorconfig.org/

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

And end_of_line is actually supported by vs, check this doc: https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022

Supported settings The editor in Visual Studio supports the core set of EditorConfig properties:

indent_style

indent_size

tab_width

end_of_line

charset

trim_trailing_whitespace

insert_final_newline

root

All Visual Studio-supported languages except for XML support EditorConfig editor settings. Also, EditorConfig supports code style conventions including language, formatting, and naming conventions for C# and Visual Basic.

sommmen
  • 6,570
  • 2
  • 30
  • 51
  • I have tried this, and it does not work for me. Visual studio happily inserts CRLF line endings when formatting the code. The other editorconfig options seem to work. – Selmar Feb 09 '23 at 17:44
  • @sommmen this doesn't work for the format document (Ctrl K + Ctrl D) despite that the docs say otherwise. Try it out yourself in the latest VS2022 17.5. Step 1) create a html document. Step 2) multiline some tabs. Step 3) Hit the format document which removes the tabs, but inserts CRLF leading to mixed lineendings. – Baklap4 Feb 27 '23 at 13:31
  • @Baklap4 in that case i'd post a bug report to msdn – sommmen Feb 27 '23 at 13:46