From 54eec79da61da76e45f9303d9ad628b286b466da Mon Sep 17 00:00:00 2001 From: sloane <1699281+sloanelybutsurely@users.noreply.github.com> Date: Sat, 13 Apr 2024 12:57:55 -0400 Subject: [PATCH] fix cmp mappings, add snippy --- .config/nix-darwin/modules/darwin/nixvim.nix | 48 +++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/.config/nix-darwin/modules/darwin/nixvim.nix b/.config/nix-darwin/modules/darwin/nixvim.nix index 276212f..bc9bf5e 100644 --- a/.config/nix-darwin/modules/darwin/nixvim.nix +++ b/.config/nix-darwin/modules/darwin/nixvim.nix @@ -24,6 +24,8 @@ nerdtree + nvim-snippy + (pkgs.vimUtils.buildVimPlugin { name = "vim-jjdescription"; src = pkgs.fetchFromGitHub { @@ -77,16 +79,58 @@ enable = true; autoEnableSources = true; settings = { - mapping.__raw = "cmp.mapping.preset.insert({})"; + snippet.expand = "function(args) require('snippy').expand_snippet(args.body) end"; + mapping.__raw = '' + cmp.mapping.preset.insert({ + [""] = cmp.mapping(function(fallback) + local has_words_before = function() + unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + end + + if cmp.visible() then + cmp.select_next_item() + elseif require('snippy').can_expand_or_advance() then + require('snippy').expand_or_advance() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, {"i", "s"}), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif require('snippy').can_jump(-1) then + require('snippy').previous() + else + fallback() + end + end, {"i", "s"}), + [""] = cmp.mapping({ + i = function(fallback) + if cmp.visible() and cmp.get_active_entry() then + cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }) + else + fallback() + end + end, + s = cmp.mapping.confirm({ select = true }), + c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), + }) + }) + ''; sources = [ { name = "nvim_lsp"; } { name = "path"; } { name = "buffer"; } + { name = "snippy"; } ]; }; cmdline = { ":" = { - mapping = { __raw = "cmp.mapping.preset.cmdline()"; }; + mapping.__raw = "cmp.mapping.preset.cmdline()"; sources = [ { name = "path"; } { name = "cmdline"; }