Help › Write SQL

Insert snippets

Insert a ready-made piece of SQL by typing a short word, fill in its fields with Tab, and make, import and export snippets of your own.

Querlyn 0.1.0 is not released yet. This help describes it ahead of release.

A snippet is a piece of SQL you insert by typing a short word. Querlyn comes with a few, and you can add your own.

Insert a snippet

  1. Type the snippet's word, for example sel. It appears in the list of suggestions with the tag snip.
  2. Take it with ↩ on macOS or Enter on Windows and Linux or ⇥ on macOS or Tab on Windows and Linux.
  3. The snippet is inserted with its first field selected. Type to replace the field.
  4. Press ⇥ on macOS or Tab on Windows and Linux to go to the next field, ⇧ on macOS or Shift on Windows and Linux and ⇥ on macOS or Tab on Windows and Linux to go back, and ⎋ on macOS or Esc on Windows and Linux when you are done.

While a snippet's fields are being filled in, the status bar says which one you are in, such as "Snippet field 1 of 3", and then the keys that go to the next field, go back and end the filling, as they are set on your computer. A field that appears in several places changes everywhere as you type. Filling ends at the last field, with ⎋ on macOS or Esc on Windows and Linux, or when you press ⇥ on macOS or Tab on Windows and Linux with the cursor outside the snippet.

When a keyword and a snippet have the same letters, the keyword comes first in the list.

The snippets that come with Querlyn

WordInsertsOffered
selSELECT … FROM … WHERE …At the start of a statement
insINSERT INTO … VALUES …At the start of a statement
updUPDATE … SET … WHERE …At the start of a statement
cteWITH … AS (…) SELECT …At the start of a statement
txnThe statements that start and commit a transaction in your database, with the cursor between themAt the start of a statement
joinJOIN … ON …After a table
caseCASE WHEN … THEN … ELSE … ENDInside an expression

Make a snippet of your own

Open Settings (⌘, on macOS or Ctrl+, on Windows and Linux) and go to Snippets, or use Command Palette › Preferences: Manage Snippets. The buttons there are New Snippet…, Edit…, Delete…, Import… and Export…. In the command palette they are Command Palette › Preferences: New Snippet…, Command Palette › Preferences: Edit Snippet…, Command Palette › Preferences: Delete Snippet…, Command Palette › Preferences: Import Snippets… and Command Palette › Preferences: Export Snippets…. Your snippets are listed first, the built-in ones under them.

  1. Choose New Snippet…. To start from SQL you already wrote, select it in the editor and choose Edit › Save Selection as Snippet… instead.

  2. Fill in the dialog:

    FieldWhat to enter
    NameWhat the snippet is. It is shown beside the prefix in the list of suggestions.
    PrefixThe word you type to get it: letters, digits and _, not starting with a digit, at most 40 characters.
    DescriptionOptional. A note about the snippet.
    DialectEvery dialect, or one database's dialect. The same prefix can be used once per dialect.
    BodyThe text to insert, with fields; see below.
  3. Choose Save.

A snippet of yours with the prefix of a built-in one replaces the built-in one.

Write a snippet's body

WriteMeaning
$1, $2A field. ⇥ on macOS or Tab on Windows and Linux visits fields in number order.
${1:table_name}A field that starts with the text table_name, selected so that typing replaces it.
The same number twiceOne field shown in two places: what you type in one appears in the other.
$0Where the cursor ends up after the last field.
\$, \}, \\A real $, } or \.

For example, this body:

SELECT count(*) FROM ${1:table} WHERE ${2:condition};$0

A snippet of several lines takes the indentation of the line it is inserted on.

Note: To put a PostgreSQL parameter such as $1 in a snippet, write \$1. Save Selection as Snippet… does this for you.

Move snippets between computers

Export… writes all your snippets to one JSON file. Import… reads such a file: a snippet with the same prefix and dialect as one you have replaces it, the others are added, and entries that are not valid are skipped and counted in the message. A file may hold at most 1,000 snippets and 4 MB.

With sync turned on, your snippets are kept the same on your computers without files; see Sync your computers.

Help for Querlyn 0.1.0. All help topics