feat: update cmp configuration for better Lua support and improved keybindings

- Updated snippet expansion function to use Lua syntax.
- Added new mappings for scrolling, completing, closing, selecting next/previous items, and confirming with replacement behavior.
- Ensured compatibility with Lua syntax in the Nix environment.
This commit is contained in:
♥ Minnie ♥ 2025-02-20 19:36:46 +08:00
parent ff3656deb7
commit 547ed496e7
Signed by: jasmine
GPG key ID: 8563E358D4E8040E

View file

@ -11,17 +11,36 @@
{name = "path";} # Filesystem paths {name = "path";} # Filesystem paths
]; ];
# The snippet expansion function. # The snippet expansion function.
snippet.expand = '' snippet.expand =
function(args) #Lua
require('luasnip').lsp_expand(args.body) ''
end function(args)
''; require('luasnip').lsp_expand(args.body)
end
'';
# cmp mappings declaration # cmp mappings declaration
mapping = { mapping = {
"<C-down>" = "cmp.mapping.select_next_item()"; "<C-s>" =
"<C-up>" = "cmp.mapping.select_prev_item()"; # Lua
"<C-esc>" = "cmp.mapping.abort()"; "cmp.mapping.scroll_docs(-4)";
"<C-CR>" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })"; "<C-t>" =
# Lua
"cmp.mapping.scroll_docs(4)";
"<C-Space>" =
# Lua
"cmp.mapping.complete()";
"<C-esc>" =
# Lua
"cmp.mapping.close()";
"<Tab>" =
# Lua
"cmp.mapping(cmp.mapping.select_next_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})";
"<S-Tab>" =
# Lua
"cmp.mapping(cmp.mapping.select_prev_item({behavior = cmp.SelectBehavior.Select}), {'i', 's'})";
"<CR>" =
# Lua
"cmp.mapping.confirm({ select = false, behavior = cmp.ConfirmBehavior.Replace })";
}; };
}; };
# Scans the sources array and enable the corresponding plugins if they are known to nixvim. # Scans the sources array and enable the corresponding plugins if they are known to nixvim.