add luasnip snippets
This commit is contained in:
@@ -23,20 +23,19 @@
|
||||
"nvim-autopairs": { "branch": "master", "commit": "ee297f215e95a60b01fde33275cc3c820eddeebe" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
|
||||
"nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "ff69ecca55d83ffc70657f260a799f79a5637831" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "056f569f71e4b726323b799b9cfacc53653bceb3" },
|
||||
"nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" },
|
||||
"nvim-sops": { "branch": "main", "commit": "cb2209562d00ef8c6c88bdec836d9edb8fbb96ef" },
|
||||
"nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "9d2acd49976e2a9da72949008df03436f781fd23" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "56f17def81478e406e3a8ec4aa727558e79786f3" },
|
||||
"nvim-treesitter": { "branch": "master", "commit": "5a2ff8b7ca5470b1011ed82ef3fdd53139ffc467" },
|
||||
"nvim-web-devicons": { "branch": "master", "commit": "19d257cf889f79f4022163c3fbb5e08639077bd8" },
|
||||
"oil.nvim": { "branch": "master", "commit": "ccab9d5e09e2d0042fbbe5b6bd05e82426247067" },
|
||||
"plenary": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
|
||||
"plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
|
||||
"search.nvim": { "branch": "main", "commit": "7b8f2315d031be73e14bc2d82386dfac15952614" },
|
||||
"telescope.nvim": { "branch": "master", "commit": "dc6fc321a5ba076697cca89c9d7ea43153276d81" },
|
||||
"telescope.nvim": { "branch": "master", "commit": "df534c3042572fb958586facd02841e10186707c" },
|
||||
"trouble.nvim": { "branch": "main", "commit": "254145ffd528b98eb20be894338e2d5c93fa02c2" },
|
||||
"undotree": { "branch": "master", "commit": "78b5241191852ffa9bb5da5ff2ee033160798c3b" },
|
||||
"vim-be-good": { "branch": "master", "commit": "4fa57b7957715c91326fcead58c1fa898b9b3625" },
|
||||
"vim-fugitive": { "branch": "master", "commit": "d4877e54cef67f5af4f950935b1ade19ed6b7370" },
|
||||
"vim-gitgutter": { "branch": "main", "commit": "7b0b5098e3e57be86bb96cfbf2b8902381eef57c" },
|
||||
"vim-helm": { "branch": "master", "commit": "ae1ebc160d2b9b90108477ab10df7a4fc501e358" }
|
||||
|
||||
@@ -3,4 +3,5 @@ require("crentist.set")
|
||||
require("crentist.autocmd")
|
||||
require("crentist.lazy_init")
|
||||
require("crentist.filetype")
|
||||
require("crentist.luasnip")
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
return {
|
||||
'neovim/nvim-lspconfig',
|
||||
tag = "v1.0.0",
|
||||
dependencies = {
|
||||
'williamboman/mason.nvim',
|
||||
'williamboman/mason-lspconfig.nvim',
|
||||
@@ -62,7 +63,7 @@ return {
|
||||
['<CR>'] = cmp.mapping({
|
||||
i = function(fallback)
|
||||
if cmp.visible() and cmp.get_active_entry() then
|
||||
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
|
||||
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
|
||||
80
lua/crentist/luasnip.lua
Normal file
80
lua/crentist/luasnip.lua
Normal file
@@ -0,0 +1,80 @@
|
||||
-- luasnip.lua
|
||||
local ls = require('luasnip')
|
||||
local s = ls.snippet
|
||||
local i = ls.insert_node
|
||||
local f = ls.function_node
|
||||
local fmt = require("luasnip.extras.fmt").fmt
|
||||
|
||||
vim.keymap.set({ "i", "s" }, "<C-l>", function()
|
||||
if ls.expand_or_jumpable() then
|
||||
ls.expand_or_jump()
|
||||
end
|
||||
end, { desc = "Snippet next argument", silent = true })
|
||||
|
||||
-- nvim config
|
||||
ls.add_snippets('lua', {
|
||||
s({ name = 'LuaSnip Snippet', trig = 'snipf' },
|
||||
fmt([[
|
||||
s({ name='<name>', trig='<trig>'},
|
||||
fmt(<template>,
|
||||
{ <inputs> },
|
||||
{ <opts> }
|
||||
)
|
||||
),
|
||||
]], {
|
||||
name = i(1, 'name'),
|
||||
trig = i(2, 'trig'),
|
||||
template = i(3, '[[]]'),
|
||||
inputs = i(4, 'nodes'),
|
||||
opts = i(5,
|
||||
'opts')
|
||||
},
|
||||
{ delimiters = '<>' }
|
||||
)
|
||||
),
|
||||
s({ name = 'Add snippets block', trig = 'add_snip' },
|
||||
fmt([[
|
||||
ls.add_snippets('<filetype>', {
|
||||
<snippets>
|
||||
})
|
||||
]],
|
||||
{ filetype = i(1, 'Filetype'), snippets = i(2, 'Snippets') },
|
||||
{ delimiters = '<>' }
|
||||
)
|
||||
),
|
||||
})
|
||||
|
||||
-- Comment block
|
||||
local function com_string(_, snip, to_multiply)
|
||||
local comment_string = vim.bo.commentstring
|
||||
local repeats = snip.captures[1]
|
||||
local result = comment_string:gsub("%%s", ""):gsub(" ", "")
|
||||
|
||||
if to_multiply then
|
||||
return string.sub(
|
||||
string.rep(result, repeats),
|
||||
0,
|
||||
repeats
|
||||
)
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
ls.add_snippets('all', {
|
||||
s({ name = 'Comment block', trig = '#com(%d+)', regTrig = true },
|
||||
fmt([[
|
||||
{comment_block}
|
||||
{comment} {comment_text}
|
||||
{comment_block}
|
||||
]],
|
||||
{
|
||||
comment_block = f(com_string, {}, { user_args = { true } }),
|
||||
comment = f(com_string, {}, { user_args = { false } }),
|
||||
comment_text = i(1,
|
||||
'Comment')
|
||||
}
|
||||
)
|
||||
),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user