Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Visual Studio mean by normalize inconsistent line endings?

People also ask

What is normalize line endings Visual Studio?

Normalizing the line endings is just making sure that all of the line ending characters are consistent. It prevents one line from ending in \r\n and another ending with \r or \n ; the first is the Windows line end pair, while the others are typically used for Mac or Linux files.

Do you want to normalize line endings?

The correct answer is almost always "Yes" and "Windows (CR LF)". The reason is that line endings in source files should almost always be consistent within the file and source files on Windows should generally have CR LF endings. There are exceptions but if if they applied to you, you would probably know about them.

What is line endings Visual Studio?

The following characters are interpreted as line breaks in Visual Studio: CR LF: Carriage return + line feed, Unicode characters 000D + 000A. LF: Line feed, Unicode character 000A. NEL: Next line, Unicode character 0085. LS: Line separator, Unicode character 2028.

How do I change the line ending code in Visual Studio?

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.


What that usually means is that you have lines ending with something other than a carriage return/line feed pair. It often happens when you copy and paste from a web page into the code editor.

Normalizing the line endings is just making sure that all of the line ending characters are consistent. It prevents one line from ending in \r\n and another ending with \r or \n; the first is the Windows line end pair, while the others are typically used for Mac or Linux files.

Since you're developing in Visual Studio, you'll obviously want to choose "Windows" from the drop down. :-)


Some lines end with \n.

Some other lines end with \r\n.

Visual Studio suggests you to make all lines end the same.


If you are using Visual Studio 2012:

Go to menu FileAdvanced Save Options → select Line endings type as Windows (CR LF).


To turn the option ON/OFF, follow the steps below from menu bar:

ToolsOptionsEnvironmentDocumentsCheck for consistent line endings on load


The file you are editing has been edited with some other editor that does not use the same line endings, resulting in a file with mixed line endings.

The ASCII characters in use for line endings are:

CR, Carriage Return
LF, Line Feed

Windows = CRLF
Mac OS 9 or earlier = CR
Unix = LF


The Wikipedia newline article might help you out. Here is an excerpt:

The different newline conventions often cause text files that have been transferred between systems of different types to be displayed incorrectly. For example, files originating on Unix or Apple Macintosh systems may appear as a single long line on some programs running on Microsoft Windows. Conversely, when viewing a file originating from a Windows computer on a Unix system, the extra CR may be displayed as ^M or at the end of each line or as a second line break.


It means that, for example, some of your lines of text with a <Carriage Return><Linefeed> (the Windows standard), and some end with just a <Linefeed> (the Unix standard).

If you click 'yes' these the end-of-lines in your source file will be converted to have all the same format.

This won't make any difference to the compiler (because end-of-lines count as mere whitespace), but it might make some difference to other tools (e.g. the 'diff' on your version control system).