nexxai's avatar
Level 37

Can I prioritize my Live Templates over the built-in suggestions in PhpStorm?

This is probably a stupid question, but is there a way to tell PhpStorm (2024.2) that if there is a conflict between a generic autocomplete suggestion and one that matches a live template that I've created, to highlight the one I've created? I've tried Googling but I've come up with nothing useful, probably because I'm looking up the wrong phrase.

I also tried asking ChatGPT but it hallucinated a setting that doesn't exist:

Navigate to Editor > General > Code Completion. Under Sorting, make sure Prioritize Live Templates is checked. This setting tells PhpStorm to highlight Live Templates before other completion options.

In that window, there is no Sorting section.

0 likes
1 reply
LaryAI's avatar
Level 58

To prioritize your Live Templates over the built-in suggestions in PhpStorm, you can adjust the settings to make your custom templates more prominent. While there isn't a direct "Prioritize Live Templates" setting, you can achieve this by tweaking the code completion settings and using a few tricks. Here's how you can do it:

  1. Adjust Live Template Abbreviations:

    • Make sure your Live Template abbreviations are unique and not conflicting with common code snippets or keywords. This will help PhpStorm recognize them more easily.
  2. Use the Tab Key for Live Templates:

    • By default, PhpStorm uses the Tab key to expand Live Templates. This can help you quickly insert your templates without relying on the autocomplete suggestions.
  3. Reorder Completion Suggestions:

    • While you can't directly prioritize Live Templates, you can influence the order of suggestions by adjusting the settings for code completion.

Here are the steps to adjust the code completion settings:

  1. Open Settings:

    • Go to File > Settings (or PhpStorm > Preferences on macOS).
  2. Navigate to Code Completion:

    • Go to Editor > General > Code Completion.
  3. Adjust Completion Settings:

    • Under the Code Completion section, you can adjust the settings to influence the order of suggestions. For example, you can enable or disable certain types of suggestions to reduce clutter and make your Live Templates more prominent.
  4. Use Live Template Prefixes:

    • You can use specific prefixes for your Live Templates to make them stand out. For example, if you prefix all your templates with lt_, typing lt_ will bring up all your Live Templates first.

Here is an example of how you can create a unique Live Template:

// Example Live Template
// Abbreviation: lt_mytemplate
// Template Text:
function ${NAME}(${PARAMS}) {
    ${BODY}
}

When you type lt_mytemplate and press Tab, PhpStorm will expand this template.

By following these steps, you can make your Live Templates more accessible and reduce conflicts with built-in suggestions. While it may not be a perfect solution, it should help you prioritize your custom templates effectively.

Please or to participate in this conversation.