Search code examples
intellij-ideaintellij-14live-templates

IDEA Live template $SELECTION$ doesn't work when not used with surround template


I'm creating some live templates in IntellIJ IDEA 14 and I need to do something similar to sout live template where I can write

something.sout

and become

System.out.println(something);

The sout live template is

System.out.println($END$);

So I tried using $END$ (which, according to Docs, should just change the cursor position after the change) but my template instead of taking the value before the dot adds itself at the end without text inside

Assert.assertFalse($END$);

so something.af is replaced with something.Assert.assertFalse();.

Then I tried using $SELECTION$ and it worked if used with COMMAND+ALT+J (Surround generator) but I get the same effect if I use the normal syntax with something.af


Solution

  • It's not a Live Template you want in this case, you want to configure a new Postfix Completion. The sout case that you were looking at was the live template version, which is, confusingly, not the same as the postfix version.

    I don't think you can create your own postfix completion templates yet, it looks like you can only enable or disable existing ones (Preferences -> Editor -> General -> Postfix Completion).

    You might want to vote for or comment on this suggestion to allow creation of custom templates.