From 206ca73ee5f74ec70f3bfc8659bb1fc22e18bcba Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 20 Jul 2025 18:29:36 +0200 Subject: [PATCH] Add luasnip instead of vsnip --- nix/user/nvim.nix | 4 ++-- nvim/filetype.lua | 20 ++++++++++++++++++++ nvim/plugins.lua | 44 +++++++++++++++++++++++++++++++++++++++----- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/nix/user/nvim.nix b/nix/user/nvim.nix index c5932cf..44ee223 100644 --- a/nix/user/nvim.nix +++ b/nix/user/nvim.nix @@ -35,9 +35,9 @@ yanky-nvim lualine-nvim undotree - vim-vsnip + luasnip nvim-cmp - cmp-vsnip + cmp_luasnip cmp-buffer cmp-path cmp-cmdline diff --git a/nvim/filetype.lua b/nvim/filetype.lua index d855162..d0a039f 100644 --- a/nvim/filetype.lua +++ b/nvim/filetype.lua @@ -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", + }), +}) diff --git a/nvim/plugins.lua b/nvim/plugins.lua index b1123ee..133d784 100644 --- a/nvim/plugins.lua +++ b/nvim/plugins.lua @@ -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({ + -- -- [''] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + -- }), + mapping = { [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), - [''] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. - }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + if ls.expandable() then + ls.expand() + else + cmp.confirm({ + select = true, + }) + end + else + fallback() + end + end), + [""] = 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" }), + [""] = 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 }, }),