How to fix inconsistent line endings for whole VS solution?

Borek Bernard picture Borek Bernard · Feb 15, 2012 · Viewed 29.5k times · Source

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?

Answer

Unchained picture Unchained · Mar 4, 2016

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.