Live Templates
Quickly scaffold common Noir code patterns with built-in templates
Live templates let you quickly insert common code patterns. Type the template prefix and press Tab to expand.
Available Templates
Section titled “Available Templates”The plugin includes 13 built-in templates, ordered by frequency of use:
1. fn - Function Declaration
Section titled “1. fn - Function Declaration”Prefix: fn + Tab
fn function_name(params) { // cursor here}Template variables:
function_name- Name of the function (editable)params- Parameter list (editable)
2. struct - Struct Declaration
Section titled “2. struct - Struct Declaration”Prefix: struct + Tab
struct StructName { // cursor here}3. let - Variable Declaration
Section titled “3. let - Variable Declaration”Prefix: let + Tab
let name = value;4. if - If Statement
Section titled “4. if - If Statement”Prefix: if + Tab
if condition { // cursor here}5. for - For Loop
Section titled “5. for - For Loop”Prefix: for + Tab
for i in 0..n { // cursor here}6. forin - For-In Loop
Section titled “6. forin - For-In Loop”Prefix: forin + Tab
for item in collection { // cursor here}7. fnmain - Main Function
Section titled “7. fnmain - Main Function”Prefix: fnmain + Tab
fn main() { // cursor here}8. else - Else Block
Section titled “8. else - Else Block”Prefix: else + Tab
else { // cursor here}9. elseif - Else-If Statement
Section titled “9. elseif - Else-If Statement”Prefix: elseif + Tab
else if condition { // cursor here}10. mod - Module Declaration
Section titled “10. mod - Module Declaration”Prefix: mod + Tab
mod module_name;11. use - Use Statement
Section titled “11. use - Use Statement”Prefix: use + Tab
use path::to::module;12. letfor - Array Comprehension
Section titled “12. letfor - Array Comprehension”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];Using Templates
Section titled “Using Templates”Basic Usage
Section titled “Basic Usage”- Type the template prefix (e.g.,
fn) - Press Tab to expand
- Edit the placeholder values
- Press Tab to move to the next placeholder
- Press Enter to finish
Example Workflow
Section titled “Example Workflow”Creating a test function:
- Type
fn+ Tab - Change
function_nametotest_add - Tab to parameters, type
a: Field, b: Field - Tab to body, type your test code
- Add
#[test]attribute above
#[test]fn test_add(a: Field, b: Field) { assert(a + b == 5);}Viewing All Templates
Section titled “Viewing All Templates”To see all available templates:
- Go to Settings → Editor → Live Templates
- Expand the Noir group
- View or edit any template
Creating Custom Templates
Section titled “Creating Custom Templates”You can create your own templates:
- Go to Settings → Editor → Live Templates
- Click + and select Live Template
- Set:
- Abbreviation: The prefix to type
- Description: What the template does
- Template text: The code to insert (use
$VAR$for placeholders)
- Click Define and select Noir as the context
- Click OK
Example Custom Template
Section titled “Example Custom Template”Create a test function template:
- Abbreviation:
test - Template text:
#[test]fn test_$NAME$() {$END$}
Variables:
$NAME$- Editable placeholder$END$- Final cursor position
Template Variables
Section titled “Template Variables”Templates use special variables:
| Variable | Description |
|---|---|
$NAME$ | Custom named placeholder |
$END$ | Final cursor position after expansion |
$SELECTION$ | Currently selected text (for surround templates) |