Live templates in phpStorm

For phpDocumentor I have the strict rule to apply a File DocBlock on the top with the necessary legal information such as copyright, license information and where to find the homepage. Anytime I add a new file, I have to open another existing sourcefile, copy the File DocBlock and paste it into the new file.

Of course this was too much effort for me so I wanted a quick way to add these DocBlocks without having to switch context. Luckily phpStorm offers such a functionality using Live Templates.

These templates allow you to define code snippets and assign an abbreviated name for them. When you need one of those in your editor all you have to do is press the shortcut key Ctrl+J, type the name of the abbreviation (of course there is auto-completion) and press ‘enter’. phpStorm will insert your code fragment of choice there and you did not have to copy-paste or switch context.

So any time I need a File DocBlock I type: <CTRL+J>phdfd<ENTER> and that’s it!

Another great thing about Live Templates is that they support placeholder locations (variables); that you can define by inserting a string surrounded by dollar signs ($). phpStorm will understand that this is meant to be a location where, after inserting the template, the mouse cursor should jump to so that you can start typing.

If you use phpStorm I really recommend investing a little time to get to know Live Templates, they can speed up your work significantly when used efficiently.