Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make all line endings (EOLs) in all files in Visual Studio Code, Unix-like?

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.

like image 441
user9303970 Avatar asked Feb 08 '18 18:02

user9303970


People also ask

How do you change line endings for all files in VS Code?

VS Code => Settings => Files: EoL And choose “\n” as EoL character if you would like your files to have Unix Style line endings and choose “\r\n” if you would like your files to have Windows Style line endings. VS Code — Eol Settings for Files. That settings applies to all new files that you create.

How do I change from CRLF to LF for all files in VS Code?

The Quick FixAt the bottom right of the screen in VS Code there is a little button that says “LF” or “CRLF”: Click that button and change it to your preference. Voila, the file you are editing now has the correct line breaks.

How do I fix Visual Studio Code line endings?

The Quick Fix for “End of line character is invalid” At the bottom right of the screen in VS Code, click the little button that says LF or CRLF . After changing it to your preference, Voila, the file you're editing now has the correct line breaks.

How do I set line endings in Visual Studio?

Go to Project> Solution Options> Source Code> Code Formatting> Text File In the Line Terminations drop box select Unix/Mac. Show activity on this post. The LF is clickable and you choose either LF or CRLF. Pretty sure that visual studio code, not visual studio.


2 Answers

The accepted answer explains how to do this for all files (use files.eol in settings), but if you ever need to override that setting there's an indicator at the bottom right that you can click on and change for this one file. Took me a while to notice that this was clickable.

See CRLF in the message bar at the bottom right

like image 80
Ian McGowan Avatar answered Oct 12 '22 12:10

Ian McGowan


I searched for a simple solution for days and didn't have any success after I found some Git commands that changed all files from CRLF to LF.

As pointed out by Mats, make sure to commit changes before executing the following commands.

In the root folder type the following.

git config core.autocrlf false  git rm --cached -r .         # Don’t forget the dot at the end  git reset --hard 
like image 37
haidar Avatar answered Oct 12 '22 12:10

haidar