From ba3d06771898945e1bcec53b73592819a70970cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Av=C3=A9?= Date: Fri, 25 Aug 2023 16:59:55 +0200 Subject: [PATCH] Switch to vim-snippy for snippets --- nvim/lua/lsp_config.lua | 48 +++++++++++++++++++++++++---------------- nvim/lua/plugins.lua | 2 +- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/nvim/lua/lsp_config.lua b/nvim/lua/lsp_config.lua index 304fcec..d935908 100644 --- a/nvim/lua/lsp_config.lua +++ b/nvim/lua/lsp_config.lua @@ -12,9 +12,9 @@ cmp.setup({ snippet = { -- REQUIRED - you must specify a snippet engine expand = function(args) - vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - -- require('snippy').expand_snippet(args.body) -- For `snippy` users. + require('snippy').expand_snippet(args.body) -- For `snippy` users. -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. end, }, @@ -25,30 +25,40 @@ cmp.setup({ mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. [""] = cmp.mapping(function(fallback) - if vim.fn["vsnip#jumpable"](1) == 1 then - feedkey("(vsnip-jump-next)", "") - elseif cmp.visible() then - cmp.select_next_item() - else - fallback() -- The fallback function sends a already mapped key. In this case, it's probably ``. - end - end, { "i", "s" }), + if cmp.visible() then + if require'snippy'.can_expand_or_advance() then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) + else + cmp.select_next_item({ behavior = cmp.SelectBehavior.Insert }) + end + elseif require'snippy'.can_expand_or_advance() then + require'snippy'.expand_or_advance() + else + fallback() + end + end, { "i", "s" }), - [''] = cmp.mapping(function() - if vim.fn["vsnip#jumpable"](1) == 1 then - feedkey("(vsnip-jump-next)", "") - elseif cmp.visible() then - cmp.select_next_item() - end - end, { "i", "s"}), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + if require'snippy'.can_expand_or_advance() then + cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select }) + else + cmp.select_prev_item({ behavior = cmp.SelectBehavior.Insert }) + end + elseif require'snippy'.can_jump(-1) then + require'snippy'.previous() + else + fallback() + end + end, { "i", "s" }), }), sources = cmp.config.sources({ { name = 'nvim_lsp' }, { name = 'path' }, - { name = 'vsnip' }, -- For vsnip users. + -- { name = 'vsnip' }, -- For vsnip users. -- { name = 'luasnip' }, -- For luasnip users. -- { name = 'ultisnips' }, -- For ultisnips users. - -- { name = 'snippy' }, -- For snippy users. + { name = 'snippy' }, -- For snippy users. }, { { name = 'buffer' }, }) diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua index 011e8ef..6dcd4d7 100644 --- a/nvim/lua/plugins.lua +++ b/nvim/lua/plugins.lua @@ -28,7 +28,7 @@ require('lazy').setup({ {"folke/trouble.nvim", dependencies = {"nvim-tree/nvim-web-devicons"}}, {"nvim-treesitter/nvim-treesitter", build = ":TSUpdate"}, {"NeogitOrg/neogit", dependencies = {"nvim-lua/plenary.nvim", "nvim-telescope/telescope.nvim", "sindrets/diffview.nvim"}, config = true}, - {'hrsh7th/nvim-cmp', dependencies = {'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-path', 'hrsh7th/vim-vsnip', 'hrsh7th/vim-vsnip-integ'}}, + {'hrsh7th/nvim-cmp', dependencies = {'hrsh7th/cmp-buffer', 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-nvim-lsp', 'hrsh7th/cmp-path', 'dcampos/nvim-snippy', 'honza/vim-snippets','dcampos/cmp-snippy' }}, {'nvim-lualine/lualine.nvim', dependencies = { 'nvim-tree/nvim-web-devicons', opt = true }}, {'nvim-telescope/telescope-fzf-native.nvim', build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release && cmake --install build --prefix build' }, {'nvim-telescope/telescope.nvim', dependencies = {'nvim-lua/plenary.nvim'}},