CotEditor reliably detects a document’s text encoding when you open it. You can also fine-tune how the detection works, depending on your needs.
When you open a document, CotEditor automatically determines its text encoding by checking, in order, BOMs (byte order marks), encoding information stored in the file’s extended attributes, the encoding declaration in the document if enabled, and the text encoding priorities you have configured.
In most cases, you don’t need to take any action, as CotEditor automatically detects a document’s text encoding. If the detected encoding doesn’t match your expectations, you can open the document by specifying a text encoding. Depending on your use case, adjusting settings related to text encoding detection may improve the detection result. For details, see Customize text encoding priorities and “Refer to the encoding declaration in a document” in the next section.
During text encoding detection, CotEditor can refer to encoding declarations written in a document. This helps when the document explicitly specifies its encoding. To turn on this feature, select the “Refer to encoding declaration in document” option in Format settings.
When this feature is enabled, CotEditor scans only the beginning of the document and uses the first encoding declaration it finds there. Comment-style declarations are checked only in the first two lines. For example, CotEditor recognizes forms such as “charset=,” “encoding=,” “@charset,” “encoding:,” and “coding:.”
Note: If you need to include wording that looks like an encoding declaration, even though it does not reflect the document’s actual text encoding, either place the correct encoding declaration before that phrase or turn off the “Refer to encoding declaration in document” option.