https://github.com/abeldekat/cmp-mini-snippets
mini.snippets completion source for nvim-cmp
https://github.com/abeldekat/cmp-mini-snippets
lua mini-nvim neovim nvim-cmp
Last synced: about 2 months ago
JSON representation
mini.snippets completion source for nvim-cmp
- Host: GitHub
- URL: https://github.com/abeldekat/cmp-mini-snippets
- Owner: abeldekat
- License: mit
- Created: 2024-12-31T08:22:17.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-01-26T10:06:24.000Z (4 months ago)
- Last Synced: 2025-03-10T00:12:51.253Z (3 months ago)
- Topics: lua, mini-nvim, neovim, nvim-cmp
- Language: Lua
- Homepage:
- Size: 29.3 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cmp_mini_snippets
This plugin is a completion source for [nvim-cmp],
providing the snippets produced by [mini.snippets].[mini.snippets] is a plugin to manage and expand snippets.
Currently, [mini.snippets] is in [beta].
## Installation
mini.deps
```lua
local add, later = MiniDeps.add, MiniDeps.laterlater(function()
add({ -- do read the installation section in the readme of mini.snippets!
source = "echasnovski/mini.snippets",
depends = { "rafamadriz/friendly-snippets" }
})
local snippets = require("mini.snippets")
-- :h MiniSnippets-examples:
snippets.setup({ snippets = { snippets.gen_loader.from_lang() }})add({ -- do read the installation section in the readme of nvim-cmp!
source = "hrsh7th/nvim-cmp",
depends = { "abeldekat/cmp-mini-snippets" }, -- this plugin
})
local cmp = require("cmp")
require'cmp'.setup({
snippet = {
expand = function(args) -- mini.snippets expands snippets from lsp...
local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert
insert({ body = args.body }) -- Insert at cursor
cmp.resubscribe({ "TextChangedI", "TextChangedP" })
require("cmp.config").set_onetime({ sources = {} })
end,
},
sources = cmp.config.sources({ { name = "mini_snippets" } }),
mapping = cmp.mapping.preset.insert(), -- more opts...
})
end)
```lazy.nvim
```lua
return {
{ -- do read the installation section in the readme of mini.snippets!
"echasnovski/mini.snippets",
dependencies = "rafamadriz/friendly-snippets",
event = "InsertEnter", -- don't depend on other plugins to load...
-- :h MiniSnippets-examples:
opts = function()
local snippets = require("mini.snippets")
return { snippets = { snippets.gen_loader.from_lang() }}
end,
},{ -- do read the installation section in the readme of nvim-cmp!
"hrsh7th/nvim-cmp",
main = "cmp",
dependencies = { "abeldekat/cmp-mini-snippets" }, -- this plugin
event = "InsertEnter",
opts = function()
local cmp = require("cmp")
return {
snippet = {
expand = function(args) -- mini.snippets expands snippets from lsp...
local insert = MiniSnippets.config.expand.insert or MiniSnippets.default_insert
insert({ body = args.body }) -- Insert at cursor
cmp.resubscribe({ "TextChangedI", "TextChangedP" })
require("cmp.config").set_onetime({ sources = {} })
end,
},
sources = cmp.config.sources({ { name = "mini_snippets" } }),
mapping = cmp.mapping.preset.insert(), -- more opts...
}
end,
},
}
```## Options
The default options can be modified in the `sources` field of the `nvim-cmp` spec.
```lua
sources = cmp.config.sources({
{
name = "mini_snippets",
option = {
-- completion items are cached using default mini.snippets context:
use_items_cache = false -- default: true
}
}
}),
```## Acknowledgments
- [cmp_luasnip] by @saadparwaiz1
- [nvim-cmp] and sources by @hrsh7th
- [mini.snippets] by @echasnovski[mini.snippets]: https://github.com/echasnovski/mini.snippets
[nvim-cmp]: https://github.com/hrsh7th/nvim-cmp
[cmp_luasnip]: https://github.com/saadparwaiz1/cmp_luasnip
[beta]: https://github.com/echasnovski/mini.nvim/issues/1428