Giter Club home page Giter Club logo

luasnip-snippets.nvim's Introduction

LuaSnip-snippets

This is a plugin that aims to provide a community driven library of LuaSnip snipets and also make it easy to add LuaSnip snippets to neovim

Installation

The following is an example of how LuaSnip is installed in doom-nvim with the packer package manager.

  use({
    "hrsh7th/nvim-cmp",
    commit = pin_commit("2e4270d02843d15510b3549354e238788ca07ca5"),
    wants = { "LuaSnip" },
    requires = {
      {
        "L3MON4D3/LuaSnip",
        commit = pin_commit("a54b21aee0423dbdce121c858ad6a88a58ef6e0f"),
        event = "BufReadPre",
        wants = "friendly-snippets",
        config = require("doom.modules.config.doom-luasnip"),
        disable = disabled_snippets,
        requires = {
          "rafamadriz/friendly-snippets",
          "luasnip_snippets.nvim",
        },
      },
      {
        "windwp/nvim-autopairs",
        commit = pin_commit("e6b1870cd2e319f467f99188f99b1c3efc5824d2"),
        config = require("doom.modules.config.doom-autopairs"),
        disable = disabled_autopairs,
        event = "BufReadPre",
      },
    },
    config = require("doom.modules.config.doom-cmp"),
    disable = disabled_lsp,
    event = "InsertEnter",
  })
 })

Config

This snippet solely aims to show how you hook LuaSnip into your config. Be sure to check out LuaSnip repo for further configurations.

return function()

    local luasnip = require("luasnip")

    -- be sure to load this first since it overwrites the snippets table.
    luasnip.snippets = require("luasnip-snippets").load_snippets()

    ...
    ...
end

User snippets

You add your own snippets by putting a lua file under lua/snippets/my-snippet-file.lua in your vimrc directory.

How to compose snippets

Here follows an example of a snippet file that you can put inside your lua/snippets directory. As you can see below the snippets are assigned to their respective language key, and hence if you like you can either put all your snippets into their own file or you can put all of your snippets in a single file - just be sure to assign them to the correct language key.

    local ls = require("luasnip")
    local s = ls.snippet
    local t = ls.text_node
    local i = ls.insert_node
    local r = require("luasnip.extras").rep

    return {
	    lua = {
            s("print_str", {
                    t("print(\""),
                    i(1, "desrc"),
                    t("\")"),
                    }),
            s("print_var1", {
                    t("print(\""),
                    i(1, "desrc"),
                    t(": \" .. "),
                    i(2, "the_variable"),
                    t(")"),
                    }),
            s("print_var2", {
                    t("print(\""),
                    i(1, "the_variable"),
                    t(": \" .. "),
                    r(1),
                    t(")"),
                    }),
            s("print_var3", {
                    t("print(\""),
                    i(1, "desrc"),
                    t(" | "),
                    i(2, "the_variable"),
                    t(" : \" .. "),
                    r(2),
                    t(")"),
                    }),
	    }
    }

Feel free to submit a PR.

I encourage anyone who wants to submit their own snippets. At the moment this plugin is quite small but it has some handy snippets already. If you decide to submit snippets please add them to their appropriate language file if it exists or create a new one if necessary. Otherwise please provide a good explanation for why you have grouped multiple language snippets into one file.

TODO

title description
setup move away from refering to how doom-nvim installs LuaSnip to a simple general installer instructions.
credits during the initial development I crawled github for various snippets. Authors need to be credited approtriately.
helpers Add more helper snippets for making it easy to create luasnippets which can seem rather daunting at first.

luasnip-snippets.nvim's People

Contributors

molleweide avatar yutkat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.