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({
+ ["<Tab>"] = 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"}),
+ ["<S-Tab>"] = 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"}),
+ ["<CR>"] = 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"; }