Create beautiful boxed comments in PhpStorm with a custom Live Template and keyboard shortcut.
#####################
# Your comment here #
#####################The box automatically adjusts to your text length!
It uses two variables:
TEXT— what you type (the banner content)LINE— auto-generated#line sized toTEXT
PhpStorm / IntelliJ IDEA → Settings… → Editor → Live Templates
File → Settings → Editor → Live Templates
- In Live Templates, click +
- Choose Live Template
- Fill fields:
- Abbreviation: e.g.
banner - Description: e.g.
Banner with # line
- Abbreviation: e.g.
Paste exactly this into Template text:
$LINE$
# $TEXT$ #
$LINE$Notes:
- The order of variables in the template text matters: it must be
LINE → TEXT → LINEto show the line above and below the text. - Leave the blank line between
LINEandTEXTif you want that spacing.
Click Edit variables… (or Define / Edit Variables depending on IDE version).
You must create two variables:
- Expression: (leave empty)
- Default value: (optional)
- “Skip if defined”: OFF
- “Always stop at” / “Stop at”: ON (so the caret stops here and you can type)
- Expression (paste exactly):
groovyScript("'#' * ((_1.length() ?: 0) + 4)", TEXT) - Default value: (leave empty)
- “Skip if defined”: ON (recommended)
- “Always stop at” / “Stop at”: OFF (you don’t want to type it)
✅ Critical rule:
In the variables table, place TEXT above LINE.
Why:
LINEdepends onTEXT.- JetBrains evaluates variables top-to-bottom; if
LINEis aboveTEXT, the line may be computed beforeTEXTis filled.
Back in the Live Template screen:
- Click Define (context)
- Pick where it should work, for example:
- PHP (if you use it in PHP)
- Plain text
- Markdown
- All (if you want it everywhere)
- Go to your editor
- Type your abbreviation (e.g.
banner) - Press Tab (or your IDE’s expand key)
- The caret stops on
TEXT— type something - The lines auto-size.