From 4bc050f3e2b4220404db18a8878c1a2f1a598d66 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 4 May 2025 21:48:49 +0200 Subject: modules/nvim/plgs/nvim-cmp: Unify key mappings by moving to the global module This makes it possible, to use the `options.desc` field to add a which-key description. I also used this chance to unify the `cmp` related key mappings in one file. --- modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix | 52 ++++++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) (limited to 'modules/by-name/nv/nvim/plgs/nvim-cmp') diff --git a/modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix b/modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix index f0754bd3..d3a20300 100644 --- a/modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix +++ b/modules/by-name/nv/nvim/plgs/nvim-cmp/default.nix @@ -21,6 +21,50 @@ in { "noselect" # Do not pre select one of the completions ]; + keymaps = [ + { + key = "hh"; + mode = ["i"]; + action.__raw = '' + function() + require('cmp').select_next_item() + end + ''; + options.desc = "go forward in completion menu"; + } + { + key = "uu"; + mode = ["i"]; + action.__raw = '' + function() + require('cmp').confirm() + end + ''; + options.desc = "confirm the selected item"; + } + + { + key = ""; + mode = ["i"]; + action.__raw = '' + function() + require('cmp').mapping.scroll_docs(-4) + end + ''; + options.desc = "Scroll up by four lines"; + } + { + key = ""; + mode = ["i"]; + action.__raw = '' + function() + require('cmp').mapping.scroll_docs(4) + end + ''; + options.desc = "Scroll down by four lines"; + } + ]; + plugins.cmp = { /* TODO: integrate this: @@ -43,13 +87,9 @@ in { */ enable = true; autoEnableSources = true; + settings = { - mapping = { - # TODO: add support for desc and which key here - "" = "cmp.mapping.scroll_docs(-4)"; # desc = "Scroll up by four lines" - "" = "cmp.mapping.scroll_docs(4)"; # desc = "Scroll down by four lines" - "HH" = "cmp.mapping.complete()"; # desc = "Confirm snipped" - }; + mapping = {}; snippet.expand = "function(args) require('luasnip').lsp_expand(args.body) end"; -- cgit 1.4.1