Skip to content

Instantly share code, notes, and snippets.

@m1roff
Created January 20, 2026 16:35
Show Gist options
  • Select an option

  • Save m1roff/ea8baaefeb2657f2fcba0de969b06d49 to your computer and use it in GitHub Desktop.

Select an option

Save m1roff/ea8baaefeb2657f2fcba0de969b06d49 to your computer and use it in GitHub Desktop.
PhpStorm Live Template: Boxed Comment

PhpStorm Live Template: Boxed Comment

Create beautiful boxed comments in PhpStorm with a custom Live Template and keyboard shortcut.

Result

#####################
# 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 to TEXT

Installation

1) Open Live Templates

macOS

PhpStorm / IntelliJ IDEASettings…EditorLive Templates

Windows / Linux

FileSettingsEditorLive Templates


2) Create a new Live Template

  1. In Live Templates, click +
  2. Choose Live Template
  3. Fill fields:
    • Abbreviation: e.g. banner
    • Description: e.g. Banner with # line

3) Paste the template body

Paste exactly this into Template text:

$LINE$
# $TEXT$ #
$LINE$

Notes:

  • The order of variables in the template text matters: it must be LINE → TEXT → LINE to show the line above and below the text.
  • Leave the blank line between LINE and TEXT if you want that spacing.

4) Define variables

Click Edit variables… (or Define / Edit Variables depending on IDE version).

You must create two variables:

Variable: TEXT

  • 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)

Variable: LINE

  • 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:

  • LINE depends on TEXT.
  • JetBrains evaluates variables top-to-bottom; if LINE is above TEXT, the line may be computed before TEXT is filled.

5) Set applicable context

Back in the Live Template screen:

  1. Click Define (context)
  2. Pick where it should work, for example:
  • PHP (if you use it in PHP)
  • Plain text
  • Markdown
  • All (if you want it everywhere)

6) Use it

  1. Go to your editor
  2. Type your abbreviation (e.g. banner)
  3. Press Tab (or your IDE’s expand key)
  4. The caret stops on TEXT — type something
  5. The lines auto-size.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment