Using Live Templates to type less

Hi :slight_smile:

Live Templates is an IntelliJ Idea feature that expands short acronyms into full blocks of code.

This repository includes a collection of them fine tuned for OPENRNDR. Install instructions here.

Example: type ora[TAB] and it gets expanded into

fun main() = application { 
    configure { }
    program {
        extend {
            
        }
    }
}

So convenient! Just create a new Kotlin file, type ora, press the TAB key and you’re rolling :slight_smile:

You can combine them with your own live templates. My settings look like this:

I added things I frequently use, for example kb expands into:

keyboard.keyDown.listen { 
    when(it.key) {
        KEY_ENTER -> 1+1
        KEY_ESCAPE -> application.exit()
    }
}

Do you have any templates that make your life easier?

A simple approach to install the live templates is to copy its XML code and paste them into the IDE:

  1. Right click on OPENRNDR.xml β†’ Open In New Window
  2. On the new window, select all the <template> ... </template> blocks (in other words, copy everything except the first and the last lines).
  3. Right click on the selected text β†’ Copy
  4. In IntelliJ Idea, go to File β†’ Settings β†’ Editor β†’ Live Templates
  5. Click on + on the right side of the window to create a Template Group called OPENRNDR.
  6. Click on OPENRNDR to select it.
  7. Press CTRL+V or Command+V to paste the copied XML templates into the OPENRNDR group.

Now you can use the live templates.

The cool thing about this copy-paste approach is that it makes it easy to share templates on a chat or post them here in the forum. For example here goes one I often use: dbc for drawer.bounds.center:

<template name="dbc" value="drawer.bounds.center" description="drawer.bounds.center" toReformat="false" toShortenFQNames="true">
  <context>
    <option name="KOTLIN" value="true" />
  </context>
</template>
2 Likes