Line endings change editor/app for the whole project

前端 未结 1 1171
半阙折子戏
半阙折子戏 2021-01-24 16:09

I have a project composed of many extensions. And these extensions use all 3 line ending types. But the server can work only with 2.

I have an editor that can change lin

相关标签:
1条回答
  • 2021-01-24 17:10

    This can be done for example with text editor UltraEdit.

    1. Click in menu Search on Replace in Files.
    2. Enter as search string \r?\n|\r
    3. Enter as replace string either \r\n to convert in all files all line endings to DOS/Windows or just \n for Unix line endings.
    4. Select Files Listed option if not already selected.
    5. Enter for In files/types the string *.* or just * or whatever is suitable to match only text files and exclude binary files. Multiple file extensions can be also specified by separating them with a semicolon like *.txt;*.htm?;*.php
    6. Select with the button ... the parent directory containing the subdirectories and files to change.
    7. Click on button Advanced or the button with the gearwheel icon to open the advanced options.
    8. Check the option Search subdirectories.
    9. Check the option Regular expressions and select the regular expression engine Perl.
    10. If the text files are encoded in UTF-16 little endian or UTF-16 big endian, check also option Use encoding and select encoding 1200 (UTF-16 LE) or 1201 (UTF-16 BE). For all other encodings like UTF-8 or ANSI the encoding option does not need to be used for this replace in files.
    11. Run the replace now with button Replace all.

    The Perl regular expression search string \r?\n|\r matches either a carriage return and linefeed pair (CRLF - DOS/Windows), or just a linefeed (LF - Unix), or just a carriage return (CR - Mac).

    All matching files will have a new modification date after running that Perl regular expression Replace All because the search expression finds all 3 line ending types.

    But it is also possible to convert only all DOS/Mac files to Unix by using as search string \r\n|\r and \n as replace string. The files containing only linefeeds and therefore being already Unix files are not modified by using this search expression.

    Use (?<!\r)\n|\r(?!\n) as search string and \r\n as replace string to convert only all Unix/Mac files to DOS/Windows. Files containing already only \r\n are not modified by this search expression.

    0 讨论(0)
提交回复
热议问题