Map files to syntax styles in CotEditor
When opening a file, CotEditor detects the document type and applies the corresponding syntax style automatically.
The File Mapping definitions in each syntax style are used for this detection.
Priority order of file mapping
CotEditor detects the corresponding syntax style in the following order:
- Filename extension
- Try determining syntax style from the filename extension. The case is basically ignored; however, case-matched ones are prioritized if multiple syntax styles are found
- e.g.: .html → HTML
- e.g.: .hTmL → HTML
- e.g.: .py → Python
- Filename
- When there is no syntax style in which the find filename extension is defined or the filename doesn’t have an extension, then try determining syntax style from the whole filename.
- e.g.: .htaccess → Apache
- e.g.: makefile → Makefile
- Shebang in the first line of the document
- When there is no corresponding syntax style for the extension and the filename, and if the first line of the document content is a shebang, then try determining syntax style from the shebang. In this trial, the interpreter names which is defined in the syntax styles are used. The interpreter can be either the last part of the path just after
#! or the next term to the path if the path targets env.
- e.g.:
#!/usr/bin/perl → Perl (interpreter: perl)
- e.g.:
#!/usr/bin/env python3 → Python (interpreter: python3)
- XML declaration
- When there is no corresponding syntax style up to here but the file content starts with an XML declaration, syntax style is automatically set to “XML.”
- e.g.:
<?xml version="1.0" encoding="utf-8"?> → XML
- None
- If no appropriate style can be found at all, the “None” syntax style would be set.
When there are multiple syntax styles in the same level like the filename extension level or the filename level, custom styles are prioritized over the bundled styles. And yet, if there are multiple corresponding styles, the first found style will be applied automatically.
File mapping conflicts
There are no conflicts among the bundled syntax styles. However, if you added custom styles or modified the bundled styles, the file mapping can conflict. You can see the existence of mapping conflicts from the Show File Mapping Conflict command in the Format pane in the Settings. If the menu item is gray-out, it means: there is no conflict.
You can just leave the file mapping conflicts as long as you can open files with your expected syntax style. There is no side issue.