Migrating from UltiSnips - L3MON4D3/LuaSnip GitHub Wiki

This page collects various tips for UltiSnips who want to quickly migrate to LuaSnip. The aim is to have all the relevant information in the same place, so that UltiSnips users can quickly get started with LuaSnip. More advanced features of LuaSnip, such as Lua snippets, are not covered.

UltiSnips features that are currently not supported

(Note that this list may be incomplete.)

Install

Install the plugin following the README.

To load snippets in a format similar to UltiSnips' snippets, you want to use the SnipMate-like loader:

require("luasnip.loaders.from_snipmate").lazy_load()

By default, the snippets should be placed in a directory named snippets in your runtimepath (see :help runtimepath). You can also specify a custom path:

require("luasnip.loaders.from_snipmate").lazy_load( paths = { "./my-snippets" } })

Here ./ specifies a path relative to $MYVIMRC. See DOC/LOADERS for more information.

Snippets

The snippet format is similar to the snipmate format. For UltiSnip snippets, you will need to remove endsnippet and indent the whole snippet by one level (using tab characters rather than space).

LuaSnip currently does not support options after the trigger word and description.

For snippets with visual placeholders, you want to replace ${VISUAL} with $TM_SELECTED_TEXT.

The priority (snippets with higher priority take precedence) and extends keywords are supported:

priority 100
extends ft1, ft2

# this is a comment
snippet c c-snippet
	c!

See DOC/snipmate for more information about the snippet format.

Keymaps

Again, refer to the README. The last two keymaps in the example (for <C-E>) are not necessary for a basic UltiSnips-like setup.

For a "supertab"-like setup with nvim-cmp, see nvim-cmp's wiki (click on "Show config" under luasnip).

Edit snippets

To create a keymap to edit snippets, see DOC/EDIT_SNIPPETS.

Nested placeholders

Nested placeholders (for example, ${1:$2}) are not enabled in LuaSnip by default. To make nested placeholders work, see the Nice Configs wiki page.

Update placeholders

Repeated placeholders (for example, the second $1 in <$1>this example</$1>) are not updated until you jump to the next placeholder. To update placeholders while typing in insert mode, add

update_events = 'TextChanged,TextChangedI'

to require("luasnip").setup() (DOC/Config-Reference).

Cancel snippet when leaving insert mode

LuaSnip allows one to jump through previous unfinished snippets even after leaving insert mode. If you find this behavior confusing you can disable it, see #656 and in particular #656 (comment).

Further information

  • See Discussion #545 for more information, and to ask your own questions about migrating from UltiSnips.
  • ejmastnak's detailed guide for LuaSnip, which also explains how to migrate to more advanced Lua snippets.
⚠️ **GitHub.com Fallback** ⚠️