Format of snippet files

Contents

To specify markers:

  • ${NN}
  • ${NN:default text}

These place markers in text, marker index NN is 0 to 40.After snippet insertion, tab-key goes to markers (and deletes them).

  • Markers can be in any order in snippet (e.g. marker 4 can be between 1 and 2)
  • Tab-key goes first to marker 1, 2, 3… and marker 0 is always last by tab-key.
  • Markers with the same index will place multi-carets, when tab-key goes to them.
  • Nested markers with def-text allowed, but only 1 level: ${2:text is {$3:here}}.
  • Macro ${NN:…} with def-text can take n lines (ending "}" on next lines, so selection will be multi-line).

The following macros are allowed in snippets text:

  • ${sel} - Replaced with text selected before snippet insertion. (If snippet called with Tab key, it's empty string.)
  • ${cp} - Replaced with clipboard text.
  • ${fname} - Replaced with current file name (w/out path and extension).
  • ${date:nnnnnn} - Replaced with current date/time formatted by string nnnnnn. See Python doc.
  • ${cmt_start} - Replaced with current lexer's "block comment" start symbols (or empty string).
  • ${cmt_end} - Replaced with current lexer's "block comment" end symbols (or empty string).
  • ${cmt_line} - Replaced with current lexer's "line comment" symbols (or empty string).

File names

Snippets are stored in separate files with extensions:

  • .cuda-snippet or .synw-snippet: main format.
  • .cuda-snips: compact format for collections of tiny snippets.

Encoding is UTF-8, no BOM. Files can be placed in any subfolder of "data/snippets" folder, file/folder names have no meaning, but it's recommented to name subfolders like AuthorName.SyntaxName, so users can easily find newly installed snippets.

Format of .cuda-snippet

First lines have format "key=value" (no spaces around "="), where "key" is one of strings:

  • "name": snippet full name, shown in dialog.
  • "id": snippet short alias for Tab-key (latin letters, digits, "_.$"), line is optional.
  • "lex": lexers list, comma-separated, for which snippet is active, line is optional, empty means snippet always active.

Then follows the line "text=" without value, and all next lines - are snippet contents.

  • Trailing blank lines are discarded.
  • Use tab-chars in text indents, they are auto replaced to spaces if current editor configured so.

Format of .cuda-snips

File contains one or several lines, one snippet per line. Empty lines, lines starting with "#" or space, are ignored. Format of lines:

  • id text
  • /N=name text
  • id /N=name text
  • id /L=lexers text
  • id /L=lexers /N=name text
  • id /L="lexers" /N="name" text

Here "id" is short alias for Tab-key, "name" (if not set, it's the same as "id") is full name for dialog, "lexers" is comma-separated lexer list, "text" is snippet contents. Contents can have escaped special chars: "\n", "\r", "\t" (tab-char), "\" (backslash).