2

in IDEA ,I can type soutto represent System.out.println();and I want to know how to make my own code abbreviation.For example, alias System.out.print(); to sounor any other names

Cyberlin
  • 195
  • 5

1 Answers1

3

This is called a Live Template in IntelliJ.

Go to File > Settings > Editor > Live Templates. From there, select Java and on the right, you'll see a plus sign. By clicking it, you'll get a 1. Live Template and that will get you a new abbreviation.

enter image description here

Name it soun and the text should be

System.out.print($END$);

Once you're done, make sure you've enabled that abbreviation by clicking the check box next to it.


The docs of IntelliJ cover in detail what the syntax is for these templates.

The $END$ syntax indicates the position of the cursor when the code snippet is complete, and you can no longer press Tab to jump to the next variable.

There are more variables to look at as well and other configurations to do!


Edit: there is an answer here for this question, but it looks like it doesn't necessarily answer the question asked on that post, so that's why I've decided to post a dedicated answer (tackling the issue at hand).

mnestorov
  • 4,116
  • 2
  • 14
  • 24
  • `$END$`seems a special syntax ,what is this.Does the doc of IDEA introduce this in detail.Anyway,it's really a helpful answer – Cyberlin Apr 07 '21 at 15:16
  • @Cyberlin I've updated my answer to explain what `$END$` means and I've provided some links! I'm glad this answer helps. If it answers your question, you can [mark it as accepted](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) :) – mnestorov Apr 07 '21 at 15:32