fix nvim snippets

This commit is contained in:
Pim Kunis 2023-10-13 12:26:56 +02:00
parent 9d62bfc350
commit 583480b3e6
2 changed files with 16 additions and 2 deletions

View file

@ -30,6 +30,8 @@
cmp-nvim-lsp cmp-nvim-lsp
friendly-snippets friendly-snippets
neodev-nvim neodev-nvim
luasnip
cmp_luasnip
]; ];
}; };

View file

@ -91,11 +91,18 @@ require("gitsigns").setup()
--[ CMP ]-- --[ CMP ]--
-- For snippets: look at https://github.com/vimjoyer/nvim-nix-video/blob/main/nvim/plugin/cmp.lua
local cmp = require('cmp') local cmp = require('cmp')
local luasnip = require('luasnip')
require('luasnip.loaders.from_vscode').lazy_load()
luasnip.config.setup {}
cmp.setup { cmp.setup {
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert { mapping = cmp.mapping.preset.insert {
['<C-n>'] = cmp.mapping.select_next_item(), ['<C-n>'] = cmp.mapping.select_next_item(),
['<C-p>'] = cmp.mapping.select_prev_item(), ['<C-p>'] = cmp.mapping.select_prev_item(),
@ -109,6 +116,8 @@ cmp.setup {
['<Tab>'] = cmp.mapping(function(fallback) ['<Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump()
else else
fallback() fallback()
end end
@ -116,6 +125,8 @@ cmp.setup {
['<S-Tab>'] = cmp.mapping(function(fallback) ['<S-Tab>'] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_prev_item() cmp.select_prev_item()
elseif luasnip.locally_jumpable(-1) then
luasnip.jump(-1)
else else
fallback() fallback()
end end
@ -123,5 +134,6 @@ cmp.setup {
}, },
sources = { sources = {
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
{ name = 'luasnip' },
}, },
} }