Home

Awesome

nvim-snippets

Allow vscode style snippets to be used with native neovim snippets vim.snippet. Also comes with support for friendly-snippets.

Features

Requirements

Installation

Using lazy.nvim

{
  "garymjr/nvim-snippets",
  keys = {
    {
      "<Tab>",
      function()
        if vim.snippet.active({ direction = 1 }) then
          vim.schedule(function()
            vim.snippet.jump(1)
          end)
          return
        end
        return "<Tab>"
      end,
      expr = true,
      silent = true,
      mode = "i",
    },
    {
      "<Tab>",
      function()
        vim.schedule(function()
          vim.snippet.jump(1)
        end)
      end,
      expr = true,
      silent = true,
      mode = "s",
    },
    {
      "<S-Tab>",
      function()
        if vim.snippet.active({ direction = -1 }) then
          vim.schedule(function()
            vim.snippet.jump(-1)
          end)
          return
        end
        return "<S-Tab>"
      end,
      expr = true,
      silent = true,
      mode = { "i", "s" },
    },
  },
}

Configuration

OptionTypeDefaultDescription
create_autocmdboolean?falseOptionally load all snippets when opening a file. Only needed if not using nvim-cmp.
create_cmp_sourceboolean?trueOptionally create a nvim-cmp source. Source name will be snippets.
friendly_snippetsboolean?falseSet to true if using friendly-snippets.
ignored_filetypesstring[]?nilFiletypes to ignore when loading snippets.
extended_filetypestable?nilFiletypes to load snippets for in addition to the default ones. ex: {typescript = {'javascript'}}
global_snippetsstring[]?{'all'}Snippets to load for all filetypes.
search_pathsstring[]{vim.fn.stdpath('config') .. '/snippets'}Paths to search for snippets.

Example Snippet

{
  "Say hello to the world": {
    "prefix": ["hw", "hello"],
    "body": "Hello, ${1:world}!$0"
  }
}

TODO