From 583480b3e6a7171aac168f431258fe70bf20c960 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Fri, 13 Oct 2023 12:26:56 +0200 Subject: [PATCH] fix nvim snippets --- home/neovim/default.nix | 2 ++ home/neovim/neovim.lua | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/home/neovim/default.nix b/home/neovim/default.nix index 3c5af06..a03249b 100644 --- a/home/neovim/default.nix +++ b/home/neovim/default.nix @@ -30,6 +30,8 @@ cmp-nvim-lsp friendly-snippets neodev-nvim + luasnip + cmp_luasnip ]; }; diff --git a/home/neovim/neovim.lua b/home/neovim/neovim.lua index a31e167..f0b20e7 100644 --- a/home/neovim/neovim.lua +++ b/home/neovim/neovim.lua @@ -91,11 +91,18 @@ require("gitsigns").setup() --[ CMP ]-- --- For snippets: look at https://github.com/vimjoyer/nvim-nix-video/blob/main/nvim/plugin/cmp.lua - local cmp = require('cmp') +local luasnip = require('luasnip') + +require('luasnip.loaders.from_vscode').lazy_load() +luasnip.config.setup {} cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, mapping = cmp.mapping.preset.insert { [''] = cmp.mapping.select_next_item(), [''] = cmp.mapping.select_prev_item(), @@ -109,6 +116,8 @@ cmp.setup { [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() else fallback() end @@ -116,6 +125,8 @@ cmp.setup { [''] = cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() + elseif luasnip.locally_jumpable(-1) then + luasnip.jump(-1) else fallback() end @@ -123,5 +134,6 @@ cmp.setup { }, sources = { { name = 'nvim_lsp' }, + { name = 'luasnip' }, }, }