Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have multiple cursor points in live templates in intelliJ IDEA using the $END$?

I can't seem to find a solution to having multiple cursor points in live templates in intellij IDEA

like image 396
Sammy Wij Avatar asked Sep 08 '17 10:09

Sammy Wij


1 Answers

There is not a way to do have the cursor end at multiple points. But you can repeat the same variable in multiple places in your template, Then as you edit that variable, it changes in all the locations.

For example, this simple example will create three variables of the same type, the type of which I enter/edit after I expand the template. The actual template is below. You can copy it to your clipboard and then paste it as a template in the Live Template settings dialog. In the example, I used a variable named EDIT.

enter image description here

<template name="meex" value="$EDIT$ a;&#10;$EDIT$ b;&#10;$EDIT$ c;" description="Multiple Edit Example" toReformat="true" toShortenFQNames="true">
  <variable name="EDIT" expression="" defaultValue="" alwaysStopAt="true" />
  <context>
    <option name="JAVA_DECLARATION" value="true" />
  </context>
</template>

UPDATE

To answer the OP's question in the comment...

To use the example template:

  1. Copy the XML snippet shown above to your clipboard. Make sure there are no leading or trailing spaces or blank lines
  2. Go to Settings (Ctrl+Alt+S / ,) > Editor > Live Templates
  3. On one of the grouping directories, such as "User", right click and select paste (or just type Ctrl+V). enter image description here
  4. This will paste the live template into the "User" group. Notice (A) the abbreviation (I chose "meex" for "Multiple Edit EXample") and (B) the "Expand with" setting. enter image description here
  5. Click OK on the Settings Dialog
  6. Use the template by typing meex (or whatever abbreviation you set in step 4A) and then hitting Tab (or whatever Key was defined in Step 4B).
  7. Start typing to the edit $EDIT$ placeholder variable, and hit Enter when done.

You can learn more about Live Templates in the IntelliJ IDEA help documentation here: https://www.jetbrains.com/help/idea/live-templates.html The best way to learn about them is to look at included templates, make a copy of them (Just right click one, select copy, then paste it elsewhere) and then edit the template and look at how the variables are configured in the "Edit variables" button on the template settings dialog. You probably do not want to edit the included templates directly so you do not corrupt them. And before playing around, you may want to back them up, just in case. Exporting them is the easiest way. See the "Sharing live templates through export/import" section at https://www.jetbrains.com/help/idea/sharing-live-templates.html

like image 64
Javaru Avatar answered Sep 30 '22 04:09

Javaru