My snippets, forked from rafamadriz/friendly-snippets.
Below is taken from the LuaSnip doc.md on how to setup the VSCode like snippets:
Luasnip is capable of loading snippets from different formats, including both the well-established VSCode and SnipMate format, as well as plain Lua files for snippets written in Lua.
All loaders share a similar interface:
require("luasnip.loaders.from_{vscode,snipmate,lua}").{lazy_,}load(opts:table|nil)
where opts
can contain the following keys:
paths
: List of paths to load. Can be a table, or a single comma-separated string. The paths may begin with~/
or./
to indicate that the path is relative to your$HOME
or to the directory where your$MYVIMRC
resides (useful to add your snippets).
If not set,runtimepath
is searched for directories that contain snippets. This procedure differs slightly for each loader:lua
: the snippet-library has to be in a directory named"luasnippets"
.snipmate
: similar to lua, but the directory has to be"snippets"
.vscode
: any directory inruntimepath
that contains apackage.json
contributing snippets.
exclude
: List of languages to exclude, empty by default.include
: List of languages to include, includes everything by default.{override,default}_priority
: These keys are passed straight to theadd_snippets
-calls and can therefore change the priority of snippets loaded from some colletion (or, in combination with{in,ex}clude
, only some of its snippets).
While load
will immediately load the snippets, lazy_load
will defer loading until
the snippets are actually needed (whenever a new buffer is created, or the
filetype is changed luasnip actually loads lazy_load
ed snippets for the
filetypes associated with this buffer. This association can be changed by
customizing load_ft_func
in setup
: the option takes a function that, passed
a bufnr
, returns the filetypes that should be loaded (fn(bufnr) -> filetypes (string[])
)).
All of the loaders support reloading, so simply editing any file contributing
snippets will reload its snippets (only in the session the file was edited in;
we use BufWritePost
for reloading, not some lower-level mechanism).
For easy editing of these files, LuaSnip provides a vim.ui.select
-based
dialog where first the filetype, and then the file can be
selected.
The rest of this is the original read me from the forked project:
Snippets collection for a set of different programming languages for faster development.
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.
This collection of snippets should work with any plugin that supports loading vscode snippets. Like for example:
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"})
This method is going to work globally on all open buffers with ruby
filetype.
Alternatively you can do set filetype=ruby.rails
so it only works on a
specific buffer, but this is going to mess up with syntax highlighting.
With vim-vsnip:
let g:vsnip_filetypes.ruby = ['rails']
For more info related to this change see #88
Use your plugin manager of choice, e.g.
-- Packer
use "rafamadriz/friendly-snippets"
-- Plug
Plug 'rafamadriz/friendly-snippets'
-- If you're using coc.nvim, you can use:
CocInstall https://github.com/rafamadriz/friendly-snippets@main
NOTE: Using nvim-compe with vim-vsnip on the videos.
- Add all included snippets to the Wiki.
A good portion of the snippets have been forked from the following repositories: