Skip to content
Superliner

A code snippet library

A library of code snippets, each a code block with its language, tagged #snippet and listed in a table. Find one again by any word in its code.

Features
Code blocks, Code Language…, the #snippet supertag, an Option field for Language, the Table view, and the palette
Keys
⌥⌘C makes a code block. ⇧⌘T tags a note. ⌘K finds a snippet.
Time
About 15 minutes, in a new workspace

Start from an empty workspace

  1. New workspace

    Choose File ▸ New Workspace… (⇧⌘N) and make a new workspace in an empty folder.

  2. Make a code block

    In the Inbox, press Return and type three backticks followed by python, then press Space. The note becomes a Python code block.

  3. Type the snippet

    Type # Parse the export, press Return, and then type the code on the next lines. Return starts a new line inside the block. Keep the first line as a comment, so the note has a name the palette and the table can show.

SpaceA typed fence makes the block.

Set the language

  1. Choose the highlight

    Click the language label on the block, or choose Format ▸ Code Language…. Type py in Find a language, then choose Python.

  2. Keep a Language field too

    The block's highlight is separate from a field. Use the field when you want to filter and sort snippets by language.

Find a language by its short name.

Tag the snippet

  1. Make the supertag

    Click the code block, then press ⇧⌘T, or choose Note ▸ Tags and Fields…. Choose Add supertag…, type snippet and choose Create #snippet. The block gets a # snippet chip.

  2. Add a Language field

    Choose Sidebar ▸ Supertags, then click snippet. Choose Note ▸ Add Field…, type Language, choose Option in the Type menu, and click Apply. Click Language on the Fields card and add the options Python, Swift, Shell and SQL, each followed by Return.

  3. Set the value

    Open the snippet, click its Language value, and choose Python.

The snippet after these steps

# Parse the export# snippet
Language: Python
The first line is the name. The Language value sits under it.

See the library as a table

  1. Show the table

    On the snippet page, choose View ▸ Show as Table. Each snippet is a row, with its first line as the name and a Language column.

  2. Sort or filter

    Click the Language header to group snippets by language. Type a word in the filter box to narrow the rows.

The first line of each snippet is its name.

Find a snippet again

  1. Search by a word

    Press ⌘K and type a word from the code, such as rows. The palette lists the snippets that contain it, each with its location.

  2. Narrow to snippets

    Type #snippet and a space before the word, so the palette searches only the notes with that supertag.

  3. Open it

    Press Return to open the snippet as a page. Press ⌘Return in the palette to open it beside the page you are reading.

The #snippet chip narrows the search to snippets.

Copy the code

Click Copy on a code block. The code is copied as plain text, without colours or formatting, and the button reads Copied for a moment. The first line, your comment, is copied too.

In any note, type \code and press Space to make a code block there, which is useful for a snippet you write on the spot. See Insert commands.

What each feature does here

FeatureWhere you set itWhat it does in this library
Code block⌥⌘C, or the typed fenceKeeps the lines, colours the code, and adds the Copy button.
Code Language…Format menuSets the highlight for the block's language.
Supertag (#snippet)⇧⌘T, Add supertag…Marks a note as a snippet, so the library and the palette chip find it.
Option field (Language)Note ▸ Add Field…, Type OptionHolds the language, for sorting and filtering in the table.
Table viewView ▸ Show as TableLists every snippet, with its Language column.
Palette⌘K, with a #snippet chipFinds a snippet by any word in its code.

Make it yours