Skip to content

Set of preconfigured snippets for different languages for NeoVim

License

Notifications You must be signed in to change notification settings

kevinm6/snippets

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snippets

Snippets collection for a set of different programming languages.

The only goal is to have one community driven repository for all kinds of snippets in all programming languages, this way you can have it all in one place.

Install

Use your plugin manager of choice, e.g.

With Lazy.nvim

{ "kevinm6/snippets" }
Neovim (native)

⚠️ Requirements:

-- Example config
{
  "garymjr/nvim-snippets",
  event = "InsertEnter",
  dependencies = { "kevinm6/snippets" },
  opts = function(_, o)
    o.extended_filetypes = {
      javascript = { "jsdoc" },
      lua = { "luadoc" },
      java = { "javadoc", "java-testing" },
      quarto = { "markdown" },
   }

   o.search_paths = { vim.fn.stdpath "data" .. "/lazy/snippets"  }
  end
}
LuaSnip

⚠️ WARNING
If you're using LuaSnip make sure to use
require("luasnip.loaders.from_vscode").lazy_load(), and add snippets as a dependency for LuaSnip, otherwise snippets might not be detected. If you don't use lazy_load() you might notice a slower startup-time

{
  "L3MON4D3/LuaSnip",
  dependencies = { "kevinm6/snippets" },
}

With Packer

use "kevinm6/snippets"

With vim-plug

Plug "kevinm6/snippets"

With coc.nvim

:CocInstall https://github.com/kevinm6/snippets@main

Usage

This collection of snippets should work with any snippet engine that supports loading vscode snippets. Like for example:

Add snippets from a framework to a filetype.

Note

This is handled by your snippet engine and has nothing to do with this snippets collection

There's extra snippets included in this repo but they are not added by default, since it would be irrelevant for people not using those frameworks. See snippets/frameworks

For example: if you want to add rails snippets to ruby.

With LuaSnip:

require'luasnip'.filetype_extend("ruby", {"rails"})

With vim-vsnip:

let g:vsnip_filetypes.ruby = ['rails']

Excluding snippets

Note

This is handled by your snippet engine and has nothing to do with this snippets collection

With LuaSnip, see help luasnip-loaders

-- Lazy
-- https://github.com/folke/lazy.nvim
{
  "hrsh7th/nvim-cmp",
  event = "InsertEnter",
  dependencies = {
    -- set as dependencies to be loaded when nvim-cmp is loaded
    "kevinm6/snippets"
    -- "hrsh7th/cmp-nvim-lsp",
    -- "hrsh7th/cmp-buffer",
  },
}

-- Packer
use "kevinm6/snippets"

-- Plug
Plug "kevinm6/snippets"

With Lazy.nvim

PLEASE NOTE: If you're using Lazy, you must add friendly-snippets as an nvim-cmp dependency, otherwise it may be loaded after other plugins. See this issue and this issue for more information. As an example:

return {
  'hrsh7th/cmp-nvim-lsp',
  dependencies = {
	  'kevinm6/snippets',
	  'L3MON4D3/LuaSnip',
  },
  config = function()
    -- the rest of your configuration
  end
}

Showcase

HTML

HTML gif

JS

JS gif

TODO

  • Add all included snippets to the Wiki.

Thanks to all contributors

Credits

A good portion of the snippets have been forked from the following repositories:

About

Set of preconfigured snippets for different languages for NeoVim

Resources

License

Stars

Watchers

Forks

Languages

  • Lua 100.0%