How to fix inconsistent line endings for whole VS solution?

后端 未结 4 1751
天涯浪人
天涯浪人 2021-01-31 14:45

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 f

4条回答
  •  盖世英雄少女心
    2021-01-31 15:16

    You can use the Replace in Files command and enable regular expressions. For example, to replace end-of-lines that have a single linefeed "\n" (like, from GitHub, for example) with the standard Windows carriage-return linefeed "\r\n", search for:

    ([^\r]|^)\n
    

    This says to create a group (that's why the parentheses are required), where the first character is either not a carriage-return or is the beginning of a line. The beginning of the line test is really only for the very beginning of the file, if it happens to start with a "\n". Following the group is a newline. So, you will match ";\n" which has the wrong end-of-line, but not "\r\n" which is the correct end-of-line.

    And replace it with:

    $1\r\n
    

    This says to keep the group ($1) and then replace the "\n" with "\r\n".

提交回复
热议问题