PyCharm 2020.2 Help

Set file type associations

PyCharm recognizes a default set of file types. Such files are parsed and highlighted according to the syntax of the corresponding languages.

If you are working with a file type that PyCharm does not recognize (for example, if it's a proprietary in-house developed file type) you can also create a custom file type.

You can configure how the IDE will parse the files by defining highlighting schemes for keywords, comments, numbers, and so on. You can also associate each file type with an extension to help the IDE identify the files of the custom formats.

Create a new file type

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | File Types.

  2. In the Recognized File Types section, click the Add button, specify the name of the new type, and provide a description.

  3. In the Syntax Highlighting section, configure case sensitivity, brace matching settings, and specify ways of defining comments:

    • Line comment: specify characters that indicate the beginning of a single-line comment.

    • Only at line start: characters that indicate the beginning of a line comment are recognized as a comment if they are located in the beginning of a line.

    • Block comment start, Block comment end: specify characters that indicate the beginning and the end of a block comment.

    • Hex prefix: specify characters that indicate that the subsequent value is a hexadecimal number (for example, 0x).

    • Number postfixes: specify characters that indicate which numeric system or unit is used. A postfix is a trailing string of characters (for example, e-3, kg).

    • Support paired braces, Support paired brackets, Support paired parens, Support string escapes: select these checkboxes to highlight paired braces, brackets, parentheses, and string escapes.

  4. In the Keywords section, you can specify up to four lists of keywords. Keywords of each list will be highlighted differently in the editor and will be auto-completed.

  5. The Ignore case checkbox indicates whether the language in files of the custom format is case-sensitive.

    Creating a new file type

Configure shebang commands for file types

PyCharm can recognize file types by the path specified on the shebang line. A shebang is a combination of characters in a script file followed by a path to the interpreter program that should execute this script. It starts with #! and it's always located on the first line of a script file.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | File Types.

  2. From the Recognized File Types list, select the file type for which you want to configure a command.

  3. In the HashBang Patters area, click the Add button (Add HashBang Pattern).

  4. In the dialog that opens, specify the path to the interpreter and click OK.

  5. Apply the changes and close the dialog.

    Configuring a shebang command for Python

Register a new file type association

If you open a file with a registered extension, PyCharm opens such a file silently in the editor.

If a file type is registered under the Files opened in associated applications category, it's opened in a relevant application. For example, PDF files are opened in the default PDF viewer. These associations come from your system settings. If you want to use different applications, make the corresponding changes in your system settings.

If PyCharm can't identify a file type, it prompts you to choose whether you want to register it, or open such a file in its associated application.

If the prompt doesn't appear automatically, right-click the necessary file in the Project tool window and select Associate with File Type from the context menu.

Registering a new file type

Change a file type association

You can associate a file type with another extension or remove an association.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | File Types.

  2. From the Recognized File Types list, select the file type that you want to associate with another extension.

  3. Use the File Name Patterns section to make the necessary changes. You can add a new extension (the Add button), remove an existing one (the Remove button), or modify an existing pattern (the Edit button).

    Configuring a custom extension

Ignore files and folders

In PyCharm, there's a list of files and folders that are completely excluded from any kind of processing. Out of the box, this list includes temporary files, service files related to version control systems, and so on:

*.hprof;*.pyc;*.pyo;*.rbc;*.yarb;*~;.DS_Store;.git;.hg;.svn;CVS;__pycache__;_svn;vssver.scc;vssver2.scc;

Modify the list of ignored files and folders

  1. In the Settings/Preferences dialog Ctrl+Alt+S, select Editor | File Types.

  2. Make the necessary changes in the Ignore files and folders list. Make sure to use the semicolon ; to separate the entries.

  3. Apply the changes and close the dialog.

Last modified: 04 August 2020