mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-26 23:16:46 +00:00
Compare commits
5 commits
457df5cbd4
...
47a1dd7f62
Author | SHA1 | Date | |
---|---|---|---|
|
47a1dd7f62 | ||
|
feccaf477a | ||
|
aa040ab538 | ||
|
71727e5378 | ||
|
34b462a744 |
3 changed files with 69 additions and 47 deletions
|
@ -4,55 +4,74 @@
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib.modules) mkIf mkMerge;
|
inherit (lib.modules) mkIf mkMerge;
|
||||||
inherit (builtins) mapAttrs;
|
inherit (lib.trivial) pipe;
|
||||||
|
inherit (lib.attrsets) mapAttrsToList;
|
||||||
|
inherit (lib.lists) flatten;
|
||||||
|
|
||||||
processLegacyMap = modes: legacyMap: [(legacyMap // {mode = modes;})];
|
legacyMapModes = {
|
||||||
|
normal = ["n"];
|
||||||
|
insert = ["i"];
|
||||||
|
select = ["s"];
|
||||||
|
visual = ["v"];
|
||||||
|
terminal = ["t"];
|
||||||
|
normalVisualOp = ["n" "v" "o"];
|
||||||
|
visualOnly = ["n" "x"];
|
||||||
|
operator = ["o"];
|
||||||
|
insertCommand = ["i" "c"];
|
||||||
|
lang = ["l"];
|
||||||
|
command = ["c"];
|
||||||
|
};
|
||||||
|
|
||||||
cfg = config.vim;
|
cfg = config.vim;
|
||||||
in {
|
in {
|
||||||
config = {
|
config = {
|
||||||
vim.keymaps = mkMerge [
|
vim.keymaps = mkMerge [
|
||||||
(mkIf cfg.disableArrows {
|
(
|
||||||
"<up>" = [
|
mkIf cfg.disableArrows [
|
||||||
{
|
{
|
||||||
|
key = "<up>";
|
||||||
mode = ["n" "i"];
|
mode = ["n" "i"];
|
||||||
action = "<nop>";
|
action = "<nop>";
|
||||||
noremap = false;
|
noremap = false;
|
||||||
}
|
}
|
||||||
];
|
|
||||||
"<down>" = [
|
|
||||||
{
|
{
|
||||||
|
key = "<down>";
|
||||||
mode = ["n" "i"];
|
mode = ["n" "i"];
|
||||||
action = "<nop>";
|
action = "<nop>";
|
||||||
noremap = false;
|
noremap = false;
|
||||||
}
|
}
|
||||||
];
|
|
||||||
"<left>" = [
|
|
||||||
{
|
{
|
||||||
|
key = "<left>";
|
||||||
mode = ["n" "i"];
|
mode = ["n" "i"];
|
||||||
action = "<nop>";
|
action = "<nop>";
|
||||||
noremap = false;
|
noremap = false;
|
||||||
}
|
}
|
||||||
];
|
|
||||||
"<right>" = [
|
|
||||||
{
|
{
|
||||||
|
key = "<right>";
|
||||||
mode = ["n" "i"];
|
mode = ["n" "i"];
|
||||||
action = "<nop>";
|
action = "<nop>";
|
||||||
noremap = false;
|
noremap = false;
|
||||||
}
|
}
|
||||||
];
|
]
|
||||||
})
|
)
|
||||||
(mapAttrs (_key: processLegacyMap ["n"]) cfg.maps.normal)
|
(
|
||||||
(mapAttrs (_key: processLegacyMap ["i"]) cfg.maps.insert)
|
pipe cfg.maps
|
||||||
(mapAttrs (_key: processLegacyMap ["s"]) cfg.maps.select)
|
[
|
||||||
(mapAttrs (_key: processLegacyMap ["v"]) cfg.maps.visual)
|
(mapAttrsToList (
|
||||||
(mapAttrs (_key: processLegacyMap ["t"]) cfg.maps.terminal)
|
oldMode: keybinds:
|
||||||
(mapAttrs (_key: processLegacyMap ["n" "v" "o"]) cfg.maps.normalVisualOp)
|
mapAttrsToList (
|
||||||
(mapAttrs (_key: processLegacyMap ["n" "x"]) cfg.maps.visualOnly)
|
key: bind:
|
||||||
(mapAttrs (_key: processLegacyMap ["o"]) cfg.maps.operator)
|
bind
|
||||||
(mapAttrs (_key: processLegacyMap ["i" "c"]) cfg.maps.insertCommand)
|
// {
|
||||||
(mapAttrs (_key: processLegacyMap ["l"]) cfg.maps.lang)
|
inherit key;
|
||||||
(mapAttrs (_key: processLegacyMap ["c"]) cfg.maps.command)
|
mode = legacyMapModes.${oldMode};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
keybinds
|
||||||
|
))
|
||||||
|
flatten
|
||||||
|
]
|
||||||
|
)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,12 @@
|
||||||
options =
|
options =
|
||||||
mapConfigOptions
|
mapConfigOptions
|
||||||
// {
|
// {
|
||||||
|
key = mkOption {
|
||||||
|
type = str;
|
||||||
|
description = ''
|
||||||
|
Key that triggers this keybind.
|
||||||
|
'';
|
||||||
|
};
|
||||||
mode = mkOption {
|
mode = mkOption {
|
||||||
type = either str (listOf str);
|
type = either str (listOf str);
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -44,31 +50,36 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
# legacy stuff
|
# legacy stuff
|
||||||
mapOption = submodule {
|
legacyMapOption = submodule {
|
||||||
options = mapConfigOptions;
|
options = mapConfigOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
mapOptions = mode:
|
mapOptions = mode:
|
||||||
mkOption {
|
mkOption {
|
||||||
description = "Mappings for ${mode} mode";
|
description = "Mappings for ${mode} mode";
|
||||||
type = attrsOf mapOption;
|
type = attrsOf legacyMapOption;
|
||||||
default = {};
|
default = {};
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
options.vim = {
|
options.vim = {
|
||||||
keymaps = mkOption {
|
keymaps = mkOption {
|
||||||
type = submodule {
|
type = listOf mapType;
|
||||||
freeformType = attrsOf (listOf mapType);
|
|
||||||
};
|
|
||||||
description = "Custom keybindings.";
|
description = "Custom keybindings.";
|
||||||
example = ''
|
example = ''
|
||||||
maps = {
|
vim.keymaps = [
|
||||||
"<leader>m" = {
|
{
|
||||||
|
key = "<leader>m";
|
||||||
mode = "n";
|
mode = "n";
|
||||||
silent = true;
|
silent = true;
|
||||||
action = "<cmd>make<CR>";
|
action = ":make<CR>";
|
||||||
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
|
}
|
||||||
};
|
{
|
||||||
|
key = "<leader>l";
|
||||||
|
mode = ["n" "x"];
|
||||||
|
silent = true;
|
||||||
|
action = "<cmd>cnext<CR>";
|
||||||
|
}
|
||||||
|
];
|
||||||
'';
|
'';
|
||||||
default = {};
|
default = {};
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (builtins) map mapAttrs filter removeAttrs attrNames;
|
inherit (builtins) map mapAttrs filter;
|
||||||
inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList;
|
inherit (lib.attrsets) mapAttrsToList filterAttrs;
|
||||||
inherit (lib.strings) concatLines concatMapStringsSep optionalString;
|
inherit (lib.strings) concatLines concatMapStringsSep;
|
||||||
inherit (lib.trivial) showWarnings pipe;
|
inherit (lib.trivial) showWarnings;
|
||||||
inherit (lib.generators) mkLuaInline;
|
inherit (lib.generators) mkLuaInline;
|
||||||
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
|
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
|
||||||
inherit (lib.nvim.lua) toLuaObject;
|
inherit (lib.nvim.lua) toLuaObject;
|
||||||
|
@ -40,17 +40,9 @@ in {
|
||||||
inherit (keymap) desc silent nowait script expr unique noremap;
|
inherit (keymap) desc silent nowait script expr unique noremap;
|
||||||
};
|
};
|
||||||
|
|
||||||
toLuaKeymap = key: bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";
|
toLuaKeymap = bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject bind.key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";
|
||||||
|
|
||||||
maps =
|
maps = concatLines (map toLuaKeymap cfg.keymaps);
|
||||||
pipe
|
|
||||||
# attrsOf (listOf mapOption)
|
|
||||||
cfg.keymaps
|
|
||||||
[
|
|
||||||
(mapAttrsToList (key: binds:
|
|
||||||
concatLines (map (toLuaKeymap key) binds)))
|
|
||||||
concatLines
|
|
||||||
];
|
|
||||||
|
|
||||||
keymaps = maps;
|
keymaps = maps;
|
||||||
in {
|
in {
|
||||||
|
|
Loading…
Reference in a new issue