Sharing Code Snippets in PhpStorm Easy Way

Code snippets, or Live Templates as they are called in PhpStorm, can help you save and reuse code. This can be any code fragment that you find yourself using often – just a single line of code like a method definition, or a hundred lines skeleton for a whole feature.

querybuilder_livetemplate

Many code snippets, such as Project-specific snippets, Framework snippets, or Library snippets, can be useful for your team and even the entire community. PhpStorm allows you to share snippets via GitHub repositories!

Some of our users already shared code snippets and provided instructions on how to install them by copying files manually. But there is a much simpler way to obtain shared snippets: You can do it by adding a read-only settings repository:

  • Go to Preferences (Settings) | Tools | Settings Repository
  • Add a read-only source with a link to GitHub repository
  • Restart PhpStorm

settings_repositories

In fact, this way you can share not only live templates, but other IDE settings too. Read more about all shareable parts here. The settings repository that you plan to share must contain the templates folder with Live Templates XML files inside:

Check out a few ready-to-use repos with snippets:

Share your live templates and send us a link!

We are brainstorming on how to improve the sharing experience. For example, maybe distribute live templates as Composer packages? We’d appreciate any comments and suggestions!

Please let us know what you think of this approach. Do you use live templates? What are they lacking to be perfect for you?

This entry was posted in Cool Feature. Bookmark the permalink.
  • Ed Eichman

    Correction: it’s not “Preferences | Tools | Settings Repository”, it’s “Settings | Tools | Settings Repository”.
    Will try it now. Will this feature also be coming to DataGrip?

    • Ed Eichman

      Ah, there is a “settings repository” plug in that can be added to DataGrip. Restarting DataGrip with the plugin installed now…

    • dlsniper

      It’s Preferences on macOS and Settings on Linux/Windows

  • Ed Eichman

    Does it have to be a GitHub repository, or ANY Git repository?

    • Eugene Morozov

      It can be any Git repository you like.

  • torlokken

    Does the Git sharing also work for File templates?