In Visual Studio you can set file's EOL to CRLF, LF, or CR, however you can do it only to a single file. I'm looking for a way that will make sure that every new file made in my solution will automatically use LF. Any ideas? Thanks in advance!
-
Good move! A simple way to get this behavior is to move from this legacy system to linux or OS/X :) – chqrlie Aug 30 '20 at 13:37
-
Open the file for output in binary mode. Or do you mean the source code editor? – Weather Vane Aug 30 '20 at 18:49
-
@chqrlie, I use a modern system and it doesn't have a problem with EOL. Use of LF is a design choice. – Wispy Aug 30 '20 at 20:17
-
1@Wispy: my comment was a humorous tease. The CRLF convention, copied from CP/M for MS/DOS in 1981 was already obsolescent then. Apple gave up on the CR convention in 2001. [Errare humanum est, perseverare diabolicum](https://fr.wikipedia.org/wiki/Errare_humanum_est,_perseverare_diabolicum) – chqrlie Aug 30 '20 at 20:50
-
@chqrlie, I've done just that actually (moved from the legacy system) – Wispy Dec 18 '22 at 09:24
3 Answers
Adding an .editorconfig
file in the root directory of the project (or solution) with the following entry should set line endings to LF
by default (for newly added lines, see the notes below).
[*]
end_of_line = lf
Quoting from the Create portable, custom editor settings with EditorConfig page.
You can add an EditorConfig file to your project or codebase to enforce consistent coding styles for everyone that works in the codebase.
The editor in Visual Studio supports the core set of EditorConfig properties:
[...]end_of_line
When you add an .editorconfig file to a folder in your file hierarchy, its settings apply to all applicable files at that level and below.
When you add an EditorConfig file to your project in Visual Studio, new lines of code are formatted according to the EditorConfig settings. The formatting of existing code is not changed unless you run one of the following commands:
Code Cleanup (Ctrl+K, Ctrl+E), which applies any white space settings, such as indent style, and selected code style settings, such as how to sort using directives.
Edit > Advanced > Format Document (or Ctrl+K, Ctrl+D in the default profile), which only applies white space settings, such as indent style. Note

- 16,984
- 2
- 27
- 49
-
1Thank you for the answer, this looks like exactly what I was looking for! – Wispy Aug 31 '20 at 12:37
-
1Note- working on a Unity project... I found my .editorconfig in the Assets folder – KevinVictor Jan 24 '22 at 01:57
-
@KevinVictor Thanks. I am not familiar with Unity projects, but going by the documentation that would mean the settings in the `.editorconfig` you found apply to files under the `Assets` folder, only. Text files elsewhere in the project would still use the defaults. Adding an `.editorconfig` file in the root directory of the project would apply to all files under it, both under `Assets` and elsewhere. – dxiv Jan 24 '22 at 02:48
If you are looking for a way to control the default translation mode for opening files in Windows, you can use _set_mode()
or set the _fmode
global variable documented here:
int _fmode = _O_BINARY;
Or at run time:
_set_mode(_O_BINARY); // defined in `<stdlib.h>`
There seems to be a way to set this more globally by modifying the Global state in the CRT, but the details are beyond my skill level in this environment.

- 131,814
- 10
- 121
- 189
Because default settings.json
contain "files.eol": "auto"
, you can browse this under VSCode documentation. You need set The default end of line character to appropriate value, e.g.:

- 967
- 11
- 18
-
5The question does not mention VS Code, and your answer does not apply to the builtin VS editor. – dxiv Aug 30 '20 at 18:22
-
2