Add luasnip instead of vsnip

This commit is contained in:
Martin
2025-07-20 18:29:36 +02:00
parent 1824ed760d
commit 206ca73ee5
3 changed files with 61 additions and 7 deletions

View File

@ -131,3 +131,23 @@ require("conform").setup({
-- lspconfig.zls.setup({ capabilities = capabilities })
-- end,
-- })
--
local get_datetime = function()
return os.date("%Y-%m-%d %H:%M")
end
local ls = require('luasnip')
ls.add_snippets("markdown", {
ls.snippet("mindful", {
-- Inserts the output of the get_datetime function as static text
ls.function_node(get_datetime, {}),
ls.text_node(" -- "),
ls.insert_node(1, "project"),
ls.text_node(" -- "),
ls.insert_node(2, "mode"),
ls.text_node(" -- "),
ls.insert_node(3, "description"),
}, {
descr = "Mindful of distractions",
}),
})

View File

@ -22,11 +22,12 @@ vim.g.windowswap_map_keys=0
local cmp = require('cmp')
local lspkind = require('lspkind')
local ls = require('luasnip')
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
ls.lsp_expand(args.body)
end,
},
@ -35,13 +36,46 @@ cmp.setup({
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
-- mapping = cmp.mapping.preset.insert({
-- -- ['<Tab>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
-- }),
mapping = {
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<Tab>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
['<CR>'] = cmp.mapping(function(fallback)
if cmp.visible() then
if ls.expandable() then
ls.expand()
else
cmp.confirm({
select = true,
})
end
else
fallback()
end
end),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif ls.locally_jumpable(1) then
ls.jump(1)
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif ls.locally_jumpable(-1) then
ls.jump(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp', priority = 1000 },
@ -50,7 +84,7 @@ cmp.setup({
{ name = 'path', priority = 600 },
{ name = 'cmp_yanky', priority = 500 },
{ name = 'git', priority = 400 },
{ name = 'vsnip', priority = 300 },
{ name = 'luasnip', priority = 300 },
{ name = 'nvim_lua', priority = 200 },
}),