# Map files to syntaxes in CotEditor on Mac

When opening a file, CotEditor detects the document type and applies the corresponding syntax automatically.

The File Mapping definitions in each syntax are used for this detection.

## Priority order of file mapping

CotEditor detects the corresponding syntax in the following order:

1. File extension
   - Try determining syntax from the file extension. The case is basically ignored; however, case-matched ones are prioritized if multiple syntaxes are found
   - e.g., .html → HTML
   - e.g., .hTmL → HTML
   - e.g., .py → Python
2. Filename
   - When there is no syntax in which the find file extension is defined or the filename doesn’t have an extension, then try determining syntax from the whole filename.
   - e.g., .htaccess → Apache
   - e.g., makefile → Makefile
3. Shebang in the first line of the document
   - When there is no corresponding syntax for the extension and the filename, and if the first line of the document contents are a shebang, then try determining syntax from the shebang. In this trial, the interpreter names which is defined in the syntaxes 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`)
4. XML declaration
   - When there is no corresponding syntax up to here but the file contents start with an XML declaration, syntax is automatically set to XML.
   - e.g., `<?xml version="1.0" encoding="utf-8"?>` → XML
5. None
   - If no appropriate syntax can be found at all, the “None” syntax would be set.

When there are multiple syntaxes in the same level like the file extension level or the filename level, custom syntaxes are prioritized over the bundled syntaxes. And yet, if there are multiple corresponding syntaxes, the firstly found syntax is used automatically.

## Modify file mapping

To define the rules to map files for a syntax, select File Mapping from the list on the left of the syntax editor, then add file extensions, filenames, or interpreters to the lists on the right side. See Define a syntax for how to open the syntax editor.

## Solve file mapping conflicts

There are no conflicts among the bundled syntaxes. However, if you added custom syntaxes or modified the bundled syntaxes, the file mapping can conflict. You can see the existence of mapping conflicts from the Show File Mapping Conflict command in the Action pop-up menu for the available syntaxes list in the Format settings. If the menu item is dimmed, 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. There is no side issue.

## See also

- Define a syntax
- Change Format settings