# Important changes on CotEditor 4.2

The way to handle line endings was changed in CotEditor 4.2.0, which was released in May 2022. Prior to version 4.2.0, all line ending codes were internally treated as LF (`U+000A`). From version 4.2.0, the actual line ending codes in document files are treated as they are. Therefore, users, especially those who have used earlier versions, require awareness of this change and may need manual migration for some settings.

For details on how the latest CotEditor treats line endings, see Handle various types of line endings.

## Line ending code in the regular expression pattern

Because the previous CotEditor handled all line ending codes as LF internally, `\n` could be used in regular expression patterns to recognize newlines, regardless of the actual line endings in the document. From CotEditor 4.2.0 on, `\n` matches only the line endings of which document actually uses LF as the line ending. If you want your documents to match any line endings regardless of the line ending character, use `\R` instead of `\n`.

`\R` is the metacharacter defined in the CUI regular expression engine, which is used in CotEditor; and matches any of a newline character, such as `U+000A` (LF), `U+000B`, `U+000C`, `U+000D` (CR), `U+0085`, `U+2028`, `U+2029`, or the sequence of `U+000D` `U+000A` (CRLF).

## Line ending handling in user settings

Scripts and regular expression patterns that assume only LF as line endings may not behave as intended in documents with other line endings than LF on CotEditor 4.2.0 and later. Those user settings require change by the user.

The following user settings require attention to the line ending handling:

- Replacement definitions for the multiple replacements
- Custom definitions in the syntax definitions
- The line ending handling in user scripts for the Script menu

## Line endings in Find & Replace

In the normal textual search and replace, the line endings contain in the search or replace string are assumed as the same as the line ending code used in the document being searched for.

That is, for example, if you search a document in which the line endings are LF for a string containing the CR line ending as a (non-regular expression) text search, all line endings in the search string will be assumed as LF. If you want to handle line endings strictly on search, use the regular expression instead.

On the other hand, regarding the text replacing with, all line endings even ones defined as a metacharacter like `\r` are assumed as the document line ending. Currently, there is no way to replace with line endings other than the document line ending and this is the same behavior as the previous CotEditor.

See Find or replace a line ending for the details of how CotEditor handles line endings in the Find & Replace.

## See also

- Handle various types of line endings
- Find or replace a line ending
- Find inconsistent line endings
- Paste text
- What’s new in CotEditor 4.2?
- Release notes