CotEditor’s search treats line endings strictly. While it allows you to search for specific line ending types, using an incorrect specification may prevent matches with the line endings you intend to find.
Tip: Typing Option-Return in a text field in the Find window breaks a line.
In normal textual search, line endings typed into the search field are treated as the current line ending of the document being searched. They therefore don’t match line endings in the document that use a different line ending character.
As in textual search, regular newline characters typed directly into the pattern are treated as the current line ending of the document being searched. By contrast, line endings specified with metacharacters or Unicode code points in the regular expression pattern are interpreted exactly as written, regardless of the document’s line ending type.
The following metacharacters indicate a line ending in regular expression patterns:
| Metacharacter | Description |
|---|---|
| \n |
|
| \r |
|
| \r\n | The sequence of |
| \R | Any kind of line endings from |
In replacement text, every line ending inserted by the replacement is normalized to the document’s line ending, even when it comes from a metacharacter such as \n or from captured text.
For example, when replacing the find text “dog\Rcow” with the replacement text “$0\r” using regular expressions in a document whose line ending type is LF (\n), the text “dog\r\ncow” in the document also matches. Theoretically, the regular expression would replace it with “dog\r\ncow\r”. However, CotEditor actually replaces it with “dog\ncow\n”.
There is currently no way to replace them with line endings other than the document line ending.