Writerside Help

Live templates

Imagine you are typing the same content again and again, it can be a specific markup element with a specific structure or attributes, or a repeating fragment, like an admonition block, for example, a warning.

Live templates can help you here. These are customizable fragments allowing you to type a few letters followed by a configurable expansion key (by default, it is Tab) and insert a frequently used fragment into your document or surround the text in the editor with some construct.

In this tutorial, you will create and reuse the live template while working on a document.

Create a Live template

For example, in this tutorial, we will create a template for a Markdown code block with some custom attributes.

Create a template group

It is handy to group templates to navigate through them easier.

  1. Go to Settings/Preferences | Editor | Live Templates.

  2. Click + on the right of the panel and select Template group.

  3. Type the group name. In our case, we called it Custom markdown. Click OK.

Create a template

  1. Select the previously created group in the list and click +. Select Live Template.

  2. Specify the abbreviation — it will be a shortcut to invoke the template. It can contain Latin letters, numbers, dots, and hyphens. For example, md-code. It should be unique within a group.

  3. (Optional) In the Description field, describe in which cases this template is intended to be used. For example, a custom collapsible Markdown code block included from a repository.

  4. In the Template text field, add the template content that will be inserted in the document later.

    Add live template body
  5. Put the $LANG$ variable to specify the language for syntax highlighting in a block.

  6. Put the $END$ variable to indicate the position of the cursor when the snippet is complete. In our case, this is src attribute where the user will specify the filename.

    ```$LANG$ ``` {src="$END$" collapsible="true" default-state="collapsed"}
  7. Define the context where the template will be used — pick Writerside Markdown templates for Markdown.

  8. Apply your changes.

From now on, you can use the Live template on the go.

Get to know other ways to create live templates.

In the example below, we used the $END$ variable. Get to know other variables in Live template variables section.

Use a Live Template

Place a cursor in the editor.

Type md-code and press Tab.

Specify the programming language and press Tab again.

Specify the filename to include the code block from it. Now you can limit the include to specific lines or code constructs.

Use live template

Writerside already has a bunch of built-in live templates for frequently used markup fragments, like tabs, tables, lists, procedures, and more. They work in both Markdown and semantic topics.

To check them and customize them for your cases, go to Settings/Preferences | Editor | Live Templates | Writerside.

Last modified: 16 May 2024