Is it possible to read custom snippets from a json file into IDEA editor just like in VSC?

Viewed 38

In Visual Studio Code there is a possibility to create a java.json, php.json etc. file in a specific folder which contains code snippets in a specific format and these custom snippets are displayed / read under Intellisense when a .java / .php file etc. is edited.

So a custom snippet can be inserted in seconds.

Is this possible somehow with IDEA? I am new to Java, and I like the IDE, but I miss this feature so much. Is there any workaround, or any idea to achieve this?

In worst case scenario I can open a VSC in the background and switch windows if I need a fast search for one of my earlier snippets but it's not that comfortable. Or I have to use only VSC and leave IDEA behind, but as far as I see IDEA has some very good core features which VSC can not have for Java.

Thank you very much

PS: about VSC snippets: https://code.visualstudio.com/docs/editor/userdefinedsnippets

PS2: LiveTemplates in IDEA seem quite useless: https://blog.jetbrains.com/idea/2020/05/write-code-faster-using-live-templates/

1 Answers

Partial answer:

  • live templates can be exported into an XML file
  • the xml file can be imported back --> thus building an xml file ready for import containing the snippets in bulk is possible.

The only question which remains if somehow this import can be automatized? By every open / by pressing a button or any idea? So the IDEA would display always the actual snippets from the xml file without the need for manually importing them.

I GOT THE SOLUTION:

The template file is located here: C:\Users\user\AppData\Roaming\JetBrains\IdeaIC2021.3\templates\Java.xml

So if I create my new snippets which overwrite this file then at every idea opening / restart I will see the modified custom snippets thus there is no need for manual import ever.

Cheers.

Related