Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix inconsistent line endings for whole VS solution?

Visual Studio will detect inconsistent line endings when opening a file and there is an option to fix it for that specific file. However, if I want to fix line endings for all files in a solution, how do I do that?

like image 851
Borek Bernard Avatar asked Feb 15 '12 14:02

Borek Bernard


People also ask

How do you change line endings in Notepad ++?

Converting using Notepad++ To write your file in this way, while you have the file open, go to the Edit menu, select the "EOL Conversion" submenu, and from the options that come up select "UNIX/OSX Format". The next time you save the file, its line endings will, all going well, be saved with UNIX-style line endings.

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.


1 Answers

Just for a more complete answer, this worked best for me:

Replace

(?<!\r)\n 

with

\r\n 

in entire solution with "regEx" option.

This will set the correct line ending in all files which didn't have the correct line ending so far. It uses the negative lookahead to check for the non-existance of a \r in front of the \n.

Be careful with the other solutions: They will either modify all lines in all files (ignoring the original line ending) or delete the last character of each line.

like image 100
Unchained Avatar answered Sep 23 '22 01:09

Unchained