Sharing Live Templates
Configuration files with definitions of custom live templates
PyCharm stores definitions of custom live template groups and templates added to predefined template groups in automatically generated configuration files <group_name>.xml
.
- For a custom group, the file contains definitions of all the templates the group includes.
- For a customized predefined group, the file contains definitions of the added templates only.
<group_name>.xml
files are stored at the following locations: - Windows:
<your_user_home_directory>\.PyCharm<version_number>\config\templates
- Linux:
~PyCharm<version>/config/templates
- macOS:
~/Library/Preferences/PyCharm<version>/templates
Sharing live templates manually through configuration files
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for macOS, and click Live Templates under Editor.
- Create the required custom template groups and update the relevant predefined groups as necessary and click OK. Based on these changes, PyCharm generates the
<group_name>.xml
files, see Location of Custom Live Templates Definitions above. - Locate the generated
<group_name>.xml
files and do one of the following:- To share the templates among your teammates, send the relevant files to them with the instruction to save the files in the
templates
folder. - To use the templates in another PyCharm installation on your computer, copy the relevant files to the
templates
folder under the relevantPyCharm<version>
folder.
- To share the templates among your teammates, send the relevant files to them with the instruction to save the files in the
Sharing live templates through export/import
PyCharm allows you to easily share live templates among your team members, numerous PyCharm installations, and even different IDE by using the standard Export/Import functionality. You can share custom template groups and updates to predefined groups.
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for macOS, and click Live Templates under Editor.
- Create the required custom template groups and update the relevant predefined groups as necessary and click OK. Based on these changes, PyCharm generates the
<group_name>.xml
files, see Location of Custom Live Templates Definitions above. - On the main menu, choose .
- In the Export Settings dialog box that opens, select the Live Template checkbox and specify the name of the
.jar
file where the exported settings will be stored. When you click OK, PyCharm generates a file with the specified named based on the.xml
configuration files stored in thetemplates
folder. - Do one of the following:
- To share the templates among your teammates, pass the generated
.jar
file to them with the following instructions:- Save the received
.jar
file on your computer. - Choose
.jar
file. on the main menu and and specify the location of the received - In the Select Components to Import dialog box that opens, select the Live Templates checkbox and click OK.
- Save the received
- To use the templates in another PyCharm installation or in another IDE on your computer, open the required installation, choose
.jar
file. on the main menu, and specify the location of the generated
- To share the templates among your teammates, pass the generated
Example of sharing templates among different IDE
Be careful when sharing templates among different IDE. If you import custom templates (updates) from a group which is predefined in the source IDE but is not predefined in the target IDE, such group will be created but will contain only the custom templates. The example below shows what happens if we add a template to a predefined group in WebStorm and then reuse it in PhpStorm.
In WebStorm, the Dart template group is predefined. If we add the t (tag pair)
template to it, this update will be saved in the Dart.xml
file:
In PhpStorm, there is no predefined template group Dart. So when we export the live templates from WebStorm and them import them into PhpStorm, a Dart group is created but it contains only one template t (tag pair)
, which we added to the group in WebStorm before export:
Sharing live templates among template groups
You can copy and move templates from one group to another.
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for macOS, and click Live Templates under Editor.
- Do one of the following:
- To copy a template to another group:
- Select the template in interest. Use Ctrl and Shift keys for multiple selection.
- Choose Copy on the context menu of the selection.
- Select the group to copy the template to and choose Padte on the context menu of the selection.
- To move a template to another group, select the required template, choose Move on the context menu of the selection and choose the group to move the template to.
- To copy a template to another group: