Here are a few approaches:
- Using Git configuration (Recommended if you’re using Git):
git config --global core.autocrlf input
This will ensure that when you commit files, Git automatically converts CRLF to LF.
- Using VS Code settings:
You can add this to your VS Code settings.json:
{
"files.eol": "\n"
}
- Using a .editorconfig file in your project root:
root = true
[*]
end_of_line = lf
4.For existing files that need conversion, you can use PowerShell:
(Get-Content yourfile.txt -Raw).Replace("`r`n", "`n") | Set-Content yourfile.txt -NoNewline -Force
The Git approach is generally recommended as it handles the conversion automatically during commits while maintaining compatibility across different operating systems.
The VS Code or .editorconfig approaches are good for ensuring new files are created with the correct line endings.
Read more guide at: https://eagerui.com/