paint-brush
How To Make Correct Line Endingsby@wagslane
1,150 reads
1,150 reads

How To Make Correct Line Endings

by Lane WagnerSeptember 12th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Unix systems (Linux and Mac) default to the LF (line feed) character for line breaks. Windows on the other hand is "special" and defaults to CR/LF (carriage return AND line feed) This is typically due to a difference in line endings. At 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.

Company Mentioned

Mention Thumbnail
featured image - How To Make Correct Line Endings
Lane Wagner HackerNoon profile picture

Ever had the problem where you submit a pull request and the diff is waaaaay bigger than it should be? The code looks identical but GitHub is telling you that it's all different! This is typically due to a difference in line endings. Unix systems (Linux and Mac) default to the LF (line feed) character for line breaks. Windows on the other hand is "special" and defaults to CR/LF (carriage return AND line feed).

The Quick Fix

If you are here to quickly fix a single file that you are having problems with, you are in luck. At 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.

The Big Fix

If you want new files to automatically have the correct line endings, then you can set the following setting in the top level of your settings.json file:

For LF:

{
    "files.eol": "\n",
}

CRLF:

{
    "files.eol": "\r\n",
}

If you set it in your global settings.json file it will apply to your entire machine. If you just want it set for the project you are working on, then edit the settings.json in the .vscode directory at the root of your project. .vscode/settings.json

Note: This setting will not automatically fix all files in your project that have the wrong line endings! It only applies to new ones. To fix the old ones go through and use the manual method.

Thanks For Reading