Skip to content
Install Plugin >

Live templates let you quickly insert common code patterns. Type the template prefix and press Tab to expand.

The plugin includes 13 built-in templates, ordered by frequency of use:

Prefix: fn + Tab

fn function_name(params) {
// cursor here
}

Template variables:

  • function_name - Name of the function (editable)
  • params - Parameter list (editable)

Prefix: struct + Tab

struct StructName {
// cursor here
}

Prefix: let + Tab

let name = value;

Prefix: if + Tab

if condition {
// cursor here
}

Prefix: for + Tab

for i in 0..n {
// cursor here
}

Prefix: forin + Tab

for item in collection {
// cursor here
}

Prefix: fnmain + Tab

fn main() {
// cursor here
}

Prefix: else + Tab

else {
// cursor here
}

Prefix: elseif + Tab

else if condition {
// cursor here
}

Prefix: mod + Tab

mod module_name;

Prefix: use + Tab

use path::to::module;

Prefix: letfor + Tab

let arr = [expression; for i in 0..n];

13. letforin - Array Comprehension with Iterator

Section titled “13. letforin - Array Comprehension with Iterator”

Prefix: letforin + Tab

let arr = [expression; for item in collection];
  1. Type the template prefix (e.g., fn)
  2. Press Tab to expand
  3. Edit the placeholder values
  4. Press Tab to move to the next placeholder
  5. Press Enter to finish

Creating a test function:

  1. Type fn + Tab
  2. Change function_name to test_add
  3. Tab to parameters, type a: Field, b: Field
  4. Tab to body, type your test code
  5. Add #[test] attribute above
#[test]
fn test_add(a: Field, b: Field) {
assert(a + b == 5);
}

To see all available templates:

  1. Go to Settings → Editor → Live Templates
  2. Expand the Noir group
  3. View or edit any template

You can create your own templates:

  1. Go to Settings → Editor → Live Templates
  2. Click + and select Live Template
  3. Set:
    • Abbreviation: The prefix to type
    • Description: What the template does
    • Template text: The code to insert (use $VAR$ for placeholders)
  4. Click Define and select Noir as the context
  5. Click OK

Create a test function template:

  • Abbreviation: test
  • Template text:
    #[test]
    fn test_$NAME$() {
    $END$
    }

Variables:

  • $NAME$ - Editable placeholder
  • $END$ - Final cursor position

Templates use special variables:

VariableDescription
$NAME$Custom named placeholder
$END$Final cursor position after expansion
$SELECTION$Currently selected text (for surround templates)