Search code examples
phpstormwebstormcode-snippets

Custom code snippet for WebStorm and PhpStorm


I use custom code snippet for Sublime Text like custom comments, function, reusable block code, CDN and more.. but I could not do that in WebStorm and PhpStorm IDE.

Here is my building block code snippet (comments) for Sublime Text:

 /*============================
            comments
   ============================*/

and this code blocks for HTML5 comments

 <!-----------------------
           comments
   ----------------------->

Moreover I'm new user for JetBrains software. Can I use custom code snippet above in JetBrains software ?


Solution

  • It's called Live Templates in JetBrains IDEs.

    Available at Settings/Preferences | Editor | Live Templates.

    You can use existing Live Templates as is, alter them to your needs or create your own.

    Creating own is better be done in own group -- they will be stored in separate config file so easier to share, no possible conflicts with built-in ones (easier to update between versions etc.). It also makes perfect sense to use separate group per language -- the same abbreviation can be used for different languages/context but abbreviation within the same group must be unique.

    BTW -- I'd say -- do not edit built-ins at all -- just disable specific built-in template and create your own version of it in separate group. This way you can always see what fix/change devs have made in new IDE version etc.

    Full official tutorial/how-to is available here: https://confluence.jetbrains.com/display/PhpStorm/Live+Templates+%28Snippets%29+in+PhpStorm


    You may also be interested in other articles: