I use Windows 10 Home and I usually use Visual Studio Code (VS Code) to edit Linux Bash scripts as well as PHP and JavaScript.
I don't develop anything dedicated for Windows and I wouldn't mind that the default EOLs for all files I edit whatsoever would be Unix like (nix).
How could I ensure that all EOLs, in all files whatsoever (from whatever file extension), are nix, in Visual Studio Code?
I ask this question after I've written a few Bash scripts in Windows with Visual Studio Code, uploaded them to GitHub as part of a project, and a senior programmer that reviewed the project told me I have Windows EOLs there and also a BOM problem that I could solve if I'll change the EOLs there to be nix (or that's what I understood, at least).
Because all my development is Linux-oriented, I would prefer that by default, any file I edit would have nix EOLs, even if it's Windows unique.
(From 20218) In your project preferences, add/edit the following configuration option:
"files.eol": "\n"
This was added as of commit 639a3cb, so you would obviously need to be using a version after that commit.
Note: Even if you have a single CRLF
in the file, the above setting will be ignored and the whole file will be converted to CRLF
. You first need to convert all CRLF
into LF
before you can open it in Visual Studio Code.
See also: https://github.com/Microsoft/vscode/issues/2957
Note (Nov 2024): In the most recent versions of VS Code the EOL setting is under File/Preferences/Settings
. Once there enter eol
in the settings filter, then choose the \n
option. No amount of changing Git settings Git cache fixed the issue for me until I changed this setting in VS Code.
Once you have changed the settings in VS Code, make sure your command line is set to your current project or directory where you want files converted to LF end of line characters and use the following command:
find . -type f -print0 | xargs -0 dos2unix -ic0 | xargs -0 dos2unix -b
. This will update all files within that directory from CRLF to LF and print the list of files updated to the command line. Note you may need to run sudo apt install dos2unix
first to install the dos2unix utility.