Unisnips is a set of tools to parse and generate expandable snippets, aiming to be the bridge between different editor/plugin/code-expand-apps. It parses snippet sources (so far only a subset of UltiSnips is supported) and converts them to different targets.
You can keep only one set of expressive code templates - AKA snippets - and free yourself the chore of rewriting snippets to fit specifications of different platforms.
🚧 Still under active development, feel free to open issues.
Parses source to a list of interchangable data for further use
See the demo site's DEBUG panel.
- TabStop
snippet subsec "most common and simple"
---------------- $1 ----------------------
----------------end $1 -------------------
endsnippet
snippet with_default "with default value"
function ${1:name} {
${2://body}
}
endsnippet
snippet nested "nested tabstop"
${0:outer and ${1://inner}}
endsnippet
- 'VISUAL' placeholder
snippet ret "return value"
ret ${VISUAL}
endsnippet
- script code block
snippet test_shell "shell code"
should print date: `! date`
endsnippet
snippet test_js "javascript code"
should print date: `!js new Date()`
endsnippet
- transformations
snippet tabstop_transformation "import vue component"
import ${1/(.*)\/([\w]*)\.vue/$2/g} from '${1}'
endsnippet
- vscode, Visual Studio Code
- atom, Atom
- sublime , Sublime Text
- jetbrains , JetBrains live template
Features \ Targets | vscode | atom | sublime | jetbrains |
---|---|---|---|---|
Simple Tabstop | ✅ | ✅ | ✅ | ✅ |
Nested Tabstop | ✅ | ❌ | ❌ | ❌ |
'VISUAL' placeholder | ✅ | ❌ | ❌ | ✅ |
Transformations | ❌ | ❌ | ❌ | |
Script code block | ❌ | ❌ | ❌ | ❌ |
A transformation can be describe as /pattern/replacement/options
.
You can reference matched groups by '$1' '$2' in replacement string, but Special Replacement String like \u
\l
is not yet supported.
And the differences between languages' regular expression will result in different behaviors.
npm i -g @unisnips/unisnips
# or
yarn global add @unisnips/unisnips
unisnips convert --target vscode -i ~/.vim/Ultisnips/typescript.snippets -o ~/vscodesnippets/typescript.json
-
Port a subset of UltiSnips parser to TypeScript, enable some basic and mostly used features
-
Add more builtin variables, may be useful in some targets (such as vscode's
$CURRENT_YEAR
) -
Parses
transformations
and convert them to vscode