Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

folke/nvim-snippets

Open more actions menu
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 

Repository files navigation

nvim-snippets

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

Features

  • Supports vscode style snippets
  • Has builtin support for friendly-snippets
  • Uses vim.snippet under the hood for snippet expansion

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

Option Type Default Description
create_autocmd boolean? false Optionally load all snippets when opening a file. Only needed if not using nvim-cmp.
create_cmp_source boolean? true Optionally create a nvim-cmp source. Source name will be snippets.
friendly_snippets boolean? false Set to true if using friendly-snippets.
ignored_filetypes string[]? nil Filetypes to ignore when loading snippets.
extended_filetypes table? nil Filetypes to load snippets for in addition to the default ones. ex: {typescript = {'javascript'}}
global_snippets string[]? {'all'} Snippets to load for all filetypes.
search_paths string[] {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

  • Automatically detect if friendly-snippets is installed
  • (Undecided) Add support for friendly-snippets package.json definitions

About

Snippet support using native neovim snippets

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.