All Projects → L3MON4D3 → LuaSnip

L3MON4D3 / LuaSnip

Licence: Apache-2.0 license
Snippet Engine for Neovim written in Lua.

Programming Languages

lua
6591 projects
Vim Script
2826 projects

Projects that are alternatives of or similar to LuaSnip

competitive-haskell
Snippets for competitive programming in Haskell
Stars: ✭ 23 (-98.08%)
Mutual labels:  snippets
sublime-node-snippets
A collection of completions/snippets for node.js v8.x
Stars: ✭ 14 (-98.83%)
Mutual labels:  snippets
FortranTip
Short instructional Fortran codes associated with Twitter @FortranTip
Stars: ✭ 39 (-96.74%)
Mutual labels:  snippets
EthereumSoliditySnippets
Set of useful snippet for efficiently using SublimeText and the Ethereum Solidity SmartContract programming language.
Stars: ✭ 27 (-97.74%)
Mutual labels:  snippets
TLDR.jl
A package for fast help and snippets
Stars: ✭ 16 (-98.66%)
Mutual labels:  snippets
common-lisp-snippets
Yasnippets for Common Lisp
Stars: ✭ 37 (-96.91%)
Mutual labels:  snippets
ZenScript
Visual Studio Code extension/Language Server for ZenScript, includes highlight, code snippet and language server(WIP). Works with 👇
Stars: ✭ 29 (-97.58%)
Mutual labels:  snippets
vscode-elixir-snippets
Elixir code snippets for VS Code
Stars: ✭ 17 (-98.58%)
Mutual labels:  snippets
easyvk
This app helps you create an apps with vk api easy!
Stars: ✭ 97 (-91.89%)
Mutual labels:  snippets
atom-perl6-editor-tools
A collection of useful Perl 6 editor tools
Stars: ✭ 19 (-98.41%)
Mutual labels:  snippets
Symfony-code-snippets
Over 100 Symfony Code Snippets for PhP code And Over 80 Twig Code Snippets. Just type the letters 'sf' to get a list of all available Symfony Code Snippets. For Twig Just Type the Tag name and you will get AutoCompletion.
Stars: ✭ 15 (-98.75%)
Mutual labels:  snippets
jquery-course
Code from my Udemy course "The Complete jQuery Course: From Beginner to Advanced"
Stars: ✭ 127 (-89.38%)
Mutual labels:  snippets
firebase-functions-snippets
Awesome Firebase Functions snippets that cannot be ignored
Stars: ✭ 68 (-94.31%)
Mutual labels:  snippets
js-jsx-snippets
Extensions for React, Redux in JS with babel and ES7 syntax
Stars: ✭ 15 (-98.75%)
Mutual labels:  snippets
CodeView
Android Library to make it easy to create an Code editor or IDE that support any languages and themes, with auto complete, auto indenting, snippets and more features
Stars: ✭ 254 (-78.76%)
Mutual labels:  snippets
competitive-programming-rs
Algorithm Snippets for Competitive Programming in Rust
Stars: ✭ 157 (-86.87%)
Mutual labels:  snippets
code-examples-manager
Software tool to manage your notes and code examples, to publish them as gists or snippets
Stars: ✭ 26 (-97.83%)
Mutual labels:  snippets
Bulma-Snippets-Sublime-Text-Plugin
Bulma Snippets Sublime Text Plugin
Stars: ✭ 13 (-98.91%)
Mutual labels:  snippets
Cpp-Data-Structures
📐 C++ Implementations of data structures & algorithms from PSU course CS162/CS163
Stars: ✭ 19 (-98.41%)
Mutual labels:  snippets
30-seconds-of-python
Short Python code snippets for all your development needs
Stars: ✭ 8,452 (+606.69%)
Mutual labels:  snippets

LuaSnip

LuaSnip

javadoc.mp4

Features

  • Tabstops
  • Text-Transformations using Lua functions
  • Conditional Expansion
  • Defining nested Snippets
  • Filetype-specific Snippets
  • Choices
  • Dynamic Snippet creation
  • Regex-Trigger
  • Autotriggered Snippets
  • Easy Postfix Snippets
  • Fast
  • Parse LSP-Style Snippets either directly in lua, as a vscode package or a snipmate snippet collection.
  • Expand LSP-Snippets with nvim-compe (or its' successor, nvim-cmp (requires cmp_luasnip))
  • Snippet history (jump back into older snippets)
  • Resolve filetype at the cursor using Treesitter

Drawbacks

  • Snippets that make use of the entire functionality of this plugin have to be defined in Lua (but 95% of snippets can be written in lsp-syntax).
  • The LSP-parser does not support Regex-Transformations.

Requirements

Neovim >= 0.5 (extmarks)

Setup

Install

  • With your preferred plugin manager i.e. vim-plug or packer (recommended).

Keymaps

" press <Tab> to expand or jump in a snippet. These can also be mapped separately
" via <Plug>luasnip-expand-snippet and <Plug>luasnip-jump-next.
imap <silent><expr> <Tab> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : '<Tab>' 
" -1 for jumping backwards.
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>

" For changing choices in choiceNodes (not strictly necessary for a basic setup).
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>'

nvim-cmp's wiki also contains an example for setting up a super-tab-like mapping.

Add Snippets

Check out the doc for a general explanation of the loaders and their benefits. The following list serves only as a short overview.

  • Vscode-like: To use existing vs-code style snippets from a plugin (eg. rafamadriz/friendly-snippets) simply install the plugin and then add

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

    somewhere in your nvim-config. LuaSnip will then load the snippets contained in the plugin on startup. You can also easily load your own custom vscode style snippets by passing the path to the custom snippet-directory to the load function:

    -- load snippets from path/of/your/nvim/config/my-cool-snippets
    require("luasnip.loaders.from_vscode").lazy_load({ paths = { "./my-cool-snippets" } })

    For more info on the vscode-loader, check the examples or documentation.

  • Snipmate-like: Very similar to Vscode-packages: install a plugin that provides snippets and call the load-function:

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

    The snipmate format is very simple, so adding custom snippets only requires a few steps:

    • add a directory beside your init.vim (or any other place that is in your runtimepath) named snippets.
    • inside that directory, create files named <filetype>.snippets and add snippets for the given filetype in it (for inspiration, check honza/vim-snippets).
      # comment
      snippet <trigger> <description>
      <snippet-body>
      snippet if C-style if
      if ($1)
      	$0

    Again, there are some examples and documentation.

  • Lua: Add the snippets by calling require("luasnip").add_snippets(filetype, snippets). An example for this can be found here.
    This can also be done much cleaner, with all the benefits that come with using a loader, by using the loader for lua

There's also a repository collecting snippets for various languages, molleweide/LuaSnip-snippets.nvim

Docs and Examples

Check DOC.md (or :help luasnip) for a short overview and in-depth explanations of the different nodes and available API.
I highly recommend looking into (or better yet, :luafileing) Examples/snippets.lua before writing snippets in lua.
The Wiki contains some pretty useful extensions to Luasnip.

【中文版】DOC in Chinese is here.

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 if delete_check_events is not enabled (set to eg. 'TextChanged').
  • update_events: Choose which events trigger an update of the active nodes' dependents. Default is just 'InsertLeave', 'TextChanged,TextChangedI' would update on every change.
  • region_check_events: Events on which to leave the current snippet if the cursor is outside its' 'region'. Disabled by default, 'CursorMoved', 'CursorHold' or 'InsertEnter' seem reasonable.
  • delete_check_events: When to check if the current snippet was deleted, and if so, remove it from the history. Off by default, 'TextChanged' (perhaps 'InsertLeave', to react to changes done in Insert mode) should work just fine (alternatively, this can also be mapped using <Plug>luasnip-delete-check).
  • store_selection_keys: Mapping for populating TM_SELECTED_TEXT and related variables (not set by default).
  • enable_autosnippets: Autosnippets are disabled by default to minimize performance penalty if unused. Set to true to enable.
  • ext_opts: Additional options passed to extmarks. Can be used to add passive/active highlight on a per-node-basis (more info in DOC.md)
  • parser_nested_assembler: Override the default behaviour of inserting a choiceNode containing the nested snippet and an empty insertNode for nested placeholders ("${1: ${2: this is nested}}"). For an example (behaviour more similar to vscode), check here
  • ft_func: Source of possible filetypes for snippets. Defaults to a function, which returns vim.split(vim.bo.filetype, ".", true), but check filetype_functions or the docs for more options.
  • load_ft_func: Function to determine which filetypes belong to a given buffer (used for lazy_loading). fn(bufnr) -> filetypes (string[]). Again, there are some examples in filetype_functions.
  • snip_env: The global environment will be extended with this table in some places, eg. in files loaded by the lua-loader.
    Setting snip_env to { some_global = "a value" } will add the global variable some_global while evaluating these files. If you mind the (probably) large number of generated warnings, consider adding the keys set here to the globals recognized by lua-language-server or add ---@diagnostic disable: undefined-global somewhere in the affected files.

Inspired by vsnip.vim

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].