1

I try to write some custom snippets. For that I install and configure Luasnip in my nvim.cmp. Also installed rafamadriz/friendly-snippets

So far it is ok; means autocompletion shows snippets from friendly-snippets. Then I tried this:

  • Create package.json (following the example found in friendly-snippets folder) in my ~/.config/nvim
  • Create a subfolder called my-snippets in ~/.config/nvim
  • Create a file html.json in that subfolder (following the syntax found in friendly-snippets folder)
  • Modify nvim.cmp so that luasnip loads snippets found in my my-snippets subfolder.
  • Save everything
  • Restart nvim

Then don't see my snippet. Also tried to disable friendly-snippets but not working too.

Here are my config :

package.json in ~/.config/nvim

    {
    "name": "friendly-snippets",
    "engines": {
        "vscode": "^1.11.0"
    },
    "contributes": {
        "snippets": [
            {
                "language": [
                    "plaintext",
                    "markdown",
                    "tex",
                    "html",
                    "global",
                    "all"
                ],
                "path": "./my-snippets/global.json"     
        },
        {
                 "language": [
                     "html",
                     "jade",
                     "pug",
                     "eruby",
                     "javascriptreact",
                     "htmldjango",
                     "astro",
             "blade"
                 ],
                 "path": "./my-snippets/html.json"
         },
      ]
    }
}

html.json in ~/.config/nvim/my-snippets

    {
    "html5c": {
        "prefix": "html5c",
        "body": [
            "<!DOCTYPE html>",
            "<html lang=\"$1en\">",
            "\t<head>",
            "\t\t<meta charset=\"UTF-8\">",
            "\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">",
            "\t\t<title>$2</title>",
            "\t\t<link href=\"$3css/style.css\" rel=\"stylesheet\">",
            "\t</head>",
            "\t<body>",
            "\t$0",
            "\t</body>",
            "</html>"
        ],
        "description": "MCP HTML - Defines a template for a html5 document w/Bootstrap",
        "scope": "text.html"
}

A fragment of nvim-cmp

   "hrsh7th/nvim-cmp",
    event = "InsertEnter",
    dependencies = {
     "hrsh7th/cmp-buffer", -- source for text in buffer
     "hrsh7th/cmp-path", -- source for file system paths
     {
       "L3MON4D3/LuaSnip",
       -- follow latest release.
       version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first   
          number of latest release)
       -- install jsregexp (optional!).
       build = "make install_jsregexp",
     },
     "saadparwaiz1/cmp_luasnip",   -- for autocompletion
     "rafamadriz/friendly-snippets", -- useful snippets
     "onsails/lspkind.nvim",       -- vs-code like pictograms
     "Jezda1337/nvim-html-css",
     },
     config = function()
     local cmp = require("cmp")

     local luasnip = require("luasnip")
     local lspkind = require("lspkind")
     -- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
    require("luasnip.loaders.from_vscode").lazy_load({ paths = {"./my-snippets"} })

So far in a html file typing html5 will not list html5c snippets.

Hope to be clear enough, I'am newbie with Nvim and lua.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.