mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2025-01-09 16:39:51 +01:00
blink: keymap wrapper
This commit is contained in:
parent
e2de9a1e27
commit
63ea5bd71f
2 changed files with 69 additions and 12 deletions
|
@ -1,7 +1,19 @@
|
||||||
{lib, ...}: let
|
{lib, ...}: let
|
||||||
inherit (lib.options) mkEnableOption mkOption literalMD;
|
inherit (lib.options) mkEnableOption mkOption literalMD;
|
||||||
inherit (lib.types) listOf str either oneOf attrsOf;
|
inherit (lib.types) listOf str either attrsOf submodule enum;
|
||||||
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
|
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
|
||||||
|
inherit (lib.nvim.binds) mkMappingOption;
|
||||||
|
|
||||||
|
keymapType = submodule {
|
||||||
|
freeformType = attrsOf (listOf (either str luaInline));
|
||||||
|
options = {
|
||||||
|
preset = mkOption {
|
||||||
|
type = enum ["default" "none" "super-tab" "enter"];
|
||||||
|
default = "none";
|
||||||
|
description = "keymap presets";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
options.vim.autocomplete.blink-cmp = {
|
options.vim.autocomplete.blink-cmp = {
|
||||||
enable = mkEnableOption "blink.cmp";
|
enable = mkEnableOption "blink.cmp";
|
||||||
|
@ -15,24 +27,38 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
keymap = mkOption {
|
keymap = mkOption {
|
||||||
type = attrsOf (oneOf [luaInline str (listOf (either str luaInline))]);
|
type = keymapType;
|
||||||
default = {};
|
default = {};
|
||||||
description = "blink.cmp keymap";
|
description = "blink.cmp keymap";
|
||||||
example = literalMD ''
|
example = literalMD ''
|
||||||
```nix
|
```nix
|
||||||
"<Up>" = ["select_prev" "fallback"];
|
vim.autocomplete.blink-cmp.setupOpts.keymap = {
|
||||||
"<C-n>" = [
|
preset = "none";
|
||||||
(lib.generators.mkLuaInline ''''
|
|
||||||
function(cmp)
|
"<Up>" = ["select_prev" "fallback"];
|
||||||
if some_condition then return end -- runs the next command
|
"<C-n>" = [
|
||||||
return true -- doesn't run the next command
|
(lib.generators.mkLuaInline ''''
|
||||||
end,
|
function(cmp)
|
||||||
'''')
|
if some_condition then return end -- runs the next command
|
||||||
"select_next"
|
return true -- doesn't run the next command
|
||||||
];
|
end,
|
||||||
|
'''')
|
||||||
|
"select_next"
|
||||||
|
];
|
||||||
|
};
|
||||||
```
|
```
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mappings = {
|
||||||
|
complete = mkMappingOption "Complete [blink.cmp]" "<C-Space>";
|
||||||
|
confirm = mkMappingOption "Confirm [blink.cmp]" "<CR>";
|
||||||
|
next = mkMappingOption "Next item [blink.cmp]" "<Tab>";
|
||||||
|
previous = mkMappingOption "Previous item [blink.cmp]" "<S-Tab>";
|
||||||
|
close = mkMappingOption "Close [blink.cmp]" "<C-e>";
|
||||||
|
scrollDocsUp = mkMappingOption "Scroll docs up [blink.cmp]" "<C-d>";
|
||||||
|
scrollDocsDown = mkMappingOption "Scroll docs down [blink.cmp]" "<C-f>";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.modules) mkIf;
|
inherit (lib.modules) mkIf;
|
||||||
inherit (lib.generators) mkLuaInline;
|
inherit (lib.generators) mkLuaInline;
|
||||||
|
|
||||||
cfg = config.vim.autocomplete.blink-cmp;
|
cfg = config.vim.autocomplete.blink-cmp;
|
||||||
|
inherit (cfg) mappings;
|
||||||
in {
|
in {
|
||||||
vim = mkIf cfg.enable {
|
vim = mkIf cfg.enable {
|
||||||
lazy.plugins.blink-cmp = {
|
lazy.plugins.blink-cmp = {
|
||||||
|
@ -35,6 +37,35 @@ in {
|
||||||
'';
|
'';
|
||||||
jump = mkLuaInline "function(direction) require('luasnip').jump(direction) end";
|
jump = mkLuaInline "function(direction) require('luasnip').jump(direction) end";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
keymap = {
|
||||||
|
${mappings.complete} = ["show" "fallback"];
|
||||||
|
${mappings.close} = ["hide" "fallback"];
|
||||||
|
${mappings.scrollDocsUp} = ["scroll_documentation_up" "fallback"];
|
||||||
|
${mappings.scrollDocsDown} = ["scroll_documentation_down" "fallback"];
|
||||||
|
${mappings.confirm} = ["accept" "fallback"];
|
||||||
|
|
||||||
|
${mappings.next} = [
|
||||||
|
"select_next"
|
||||||
|
"snippet_forward"
|
||||||
|
(mkLuaInline ''
|
||||||
|
function(cmp)
|
||||||
|
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
|
has_words_before = col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||||
|
|
||||||
|
if has_words_before then
|
||||||
|
return cmp.show()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'')
|
||||||
|
"fallback"
|
||||||
|
];
|
||||||
|
${mappings.previous} = [
|
||||||
|
"select_prev"
|
||||||
|
"snippet_backward"
|
||||||
|
"fallback"
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue