/LuaSnip

Snippet Engine for Neovim written in Lua.

Primary LanguageLuaApache License 2.0Apache-2.0

LuaSnip

javadoc.mp4

Features

  • Tabstops
  • Text-Transformations using Lua functions
  • Conditional Expansion
  • Defining nested Snippets
  • Filetype-specific Snippets
  • Choices
  • Dynamic Snippet creation
  • Regex-Trigger
  • Fast, small, simple
  • Parse LSP-Style Snippets (Does not, however, support Regex-Transformations)
  • Expand LSP-Snippets with nvim-compe
  • Snippet history (jump back into older snippets)

Drawbacks

  • Snippets that make use of the entire functionality of this plugin have to be defined in Lua.

Requirements

Neovim >= 0.5 (extmarks)

Setup

  • Install using eg. vim-plug
  • Add mappings (Example from my config)
    imap <silent><expr> <Tab> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : '<Tab>' 
    inoremap <silent> <S-Tab> <cmd>lua require'luasnip'.jump(-1)<Cr>
    
    snoremap <silent> <Tab> <cmd>lua require('luasnip').jump(1)<Cr>
    snoremap <silent> <S-Tab> <cmd>lua require('luasnip').jump(-1)<Cr>
    
    imap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>'
    smap <silent><expr> <C-E> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-E>'
  • Add Snippets: Snippets have to be added to the require'luasnip'.snippets-table. Examples contains more details, for actual snippets take a look at examples or my Snippets.

For Supertab-like functionality with compe, check out #1.

Config

  • history: If true, Snippets that were exited can still be jumped back into. As Snippets are not removed when their text is deleted, they have to be removed manually via LuasnipUnlinkCurrent.
  • updateevents: Choose which events trigger an update of the active nodes' dependents. Default is just 'InsertLeave', 'TextChanged,TextChangedI' would update on every change.

Inspired by vsnip.vim