Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code snippets in PhpStorm

I use PhpStorm. I want to make snippets of code and then assign shortcuts to them. I can do it in NetBeans, but in PhpStorm I don't know how to make them.

For example, to add console.log(); in NetBeans, I only type con + space. con is the shortcut that I had defined.

like image 661
Aladdin Mhemed Avatar asked Mar 29 '12 05:03

Aladdin Mhemed


People also ask

What is a snippet in code?

A code Snippet is a programming term that refers to a small portion of re-usable source code, machine code, or text. Snippets help programmers reduce the time it takes to type in repetitive information while coding. Code Snippets are a feature on most text editors, code editors, and IDEs.

Is PhpStorm a text editor?

When you need to edit just one file without creating or loading the whole project in PhpStorm, you can use the LightEdit mode. Keep in mind that the LightEdit mode works as a text-like editor, and it doesn't support the usual IDE editor features such as code completion, or code navigation.

How do you make a snippet in clion?

To expand a code snippet, type the corresponding template abbreviation and press Tab . Keep pressing Tab to jump from one variable in the template to the next one. Press Shift+Tab to move to the previous variable.


1 Answers

In IntelliJ (the Java IDE) or PhpStorm (the PHP IDE) it is called Live Templates.

Go to Settings and start typing "live templates" in the search box. On the right panel you can edit and create such templates.

So in your case, you simply type "con" in the abbreviation text box and "console.log();" in the template box text area below. You may even change, with which action you want to expand the template (Tab is default, space and enter are possible).

The live template thing is much more complex than what I wrote above. You can use variables and some context information. For further reading, I suggest the JetBrains / PhpStorm documentation.

like image 144
synopia Avatar answered Sep 21 '22 15:09

synopia