From 5218a5331d971b14fc6089ce8148e50219e65d4e Mon Sep 17 00:00:00 2001 From: cy Date: Sat, 11 Jan 2025 00:08:00 -0500 Subject: [PATCH] fix cmp mapping --- home/nixvim/default.nix | 91 ++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/home/nixvim/default.nix b/home/nixvim/default.nix index f03967a..48bf914 100644 --- a/home/nixvim/default.nix +++ b/home/nixvim/default.nix @@ -72,41 +72,68 @@ plugins.cmp = { enable = true; - settings.sources = [ - { name = "nvim_lsp"; } - { name = "luasnip"; } - { name = "buffer"; } - { name = "nvim_lua"; } - { name = "path"; } - ]; - - settings.mappings = { - "" = "cmp.mapping.abort()"; - "" = "cmp.mapping.select_next_item()"; - "" = "cmp.mapping.select_prev_item()"; - "" = "cmp.mapping.scroll_docs(-4)"; - "" = "cmp.mapping.scroll_docs(4)"; - "" = "cmp.mapping.confirm({ select = true })"; - "" = '' - cmp.mapping(function(fallback) - if require("luasnip").expand_or_jumpable() then - require("luasnip").expand_or_jump() - else - fallback() - end - end,{"i","s"}) - ''; - "" = '' - cmp.mapping(function(fallback) - if require("luasnip").jumpable(-1) then - require("luasnip").jump(-1) - else - fallback() - end - end,{"i","s"}) + settings = { + formatting.fields = [ + "abbr" + "kind" + "menu" + ]; + experimental = { + ghost_text = true; + }; + snippet.expand = '' + function(args) require('luasnip').lsp_expand(args.body) end ''; + sources = [ + { name = "nvim_lsp"; } + { name = "emoji"; } + { name = "luasnip"; } + { name = "buffer"; } + { name = "path"; } + ]; + mapping = { + "" = "cmp.mapping.abort()"; + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.select_prev_item()"; + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + "" = '' + cmp.mapping(function(fallback) + if cmp.visible() then + if require("luasnip").expandable() then + require("luasnip").expand() + else + cmp.confirm({ + select = true, + }) + end + else + fallback() + end + end) + ''; + "" = '' + cmp.mapping(function(fallback) + if require("luasnip").jumpable(1) then + require("luasnip").jump(1) + else + fallback() + end + end,{"i","s"}) + ''; + "" = '' + cmp.mapping(function(fallback) + if require("luasnip").jumpable(-1) then + require("luasnip").jump(-1) + else + fallback() + end + end,{"i","s"}) + ''; + }; }; }; + plugins.lsp = { enable = true; keymaps.lspBuf = {