mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-23 05:40:44 +00:00
Compare commits
42 commits
f905acaf05
...
51035c5468
Author | SHA1 | Date | |
---|---|---|---|
|
51035c5468 | ||
|
477f2fb8c7 | ||
|
7bace58ab4 | ||
|
ca86aaa3af | ||
|
c991b2adea | ||
|
6d42de8aba | ||
|
39ebfbcd98 | ||
|
0daad3e51a | ||
|
7075872810 | ||
|
4e13acfac3 | ||
|
3a88caeda6 | ||
|
4c230a0460 | ||
|
cfaa2e3e77 | ||
|
217079b546 | ||
|
6fe0103209 | ||
|
6d2d9cd60e | ||
|
b1cc8bb27b | ||
|
90dd876c53 | ||
|
146fcf25e6 | ||
|
5eadc2937d | ||
|
f683cd36e0 | ||
|
bd6c228e5c | ||
|
d660aae9be | ||
|
4014ab0a01 | ||
|
659c4b5ca2 | ||
|
23c6f319cd | ||
|
57828912bb | ||
|
56a3d45ac7 | ||
|
5745fd8103 | ||
|
5a045d2ea0 | ||
|
7648cb8c7e | ||
|
6e3292f2c4 | ||
|
7abd0f8626 | ||
|
3800a1c016 | ||
|
6cd3363942 | ||
|
6d7d5ee190 | ||
|
b6c1a7145e | ||
|
b2eae85e79 | ||
|
feccaf477a | ||
|
aa040ab538 | ||
|
71727e5378 | ||
|
34b462a744 |
3 changed files with 66 additions and 44 deletions
|
@ -4,55 +4,74 @@
|
|||
...
|
||||
}: let
|
||||
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;
|
||||
in {
|
||||
config = {
|
||||
vim.keymaps = mkMerge [
|
||||
(mkIf cfg.disableArrows {
|
||||
"<up>" = [
|
||||
(
|
||||
mkIf cfg.disableArrows [
|
||||
{
|
||||
key = "<up>";
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
}
|
||||
];
|
||||
"<down>" = [
|
||||
{
|
||||
key = "<down>";
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
}
|
||||
];
|
||||
"<left>" = [
|
||||
{
|
||||
key = "<left>";
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
}
|
||||
];
|
||||
"<right>" = [
|
||||
{
|
||||
key = "<right>";
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
}
|
||||
];
|
||||
})
|
||||
(mapAttrs (_key: processLegacyMap ["n"]) cfg.maps.normal)
|
||||
(mapAttrs (_key: processLegacyMap ["i"]) cfg.maps.insert)
|
||||
(mapAttrs (_key: processLegacyMap ["s"]) cfg.maps.select)
|
||||
(mapAttrs (_key: processLegacyMap ["v"]) cfg.maps.visual)
|
||||
(mapAttrs (_key: processLegacyMap ["t"]) cfg.maps.terminal)
|
||||
(mapAttrs (_key: processLegacyMap ["n" "v" "o"]) cfg.maps.normalVisualOp)
|
||||
(mapAttrs (_key: processLegacyMap ["n" "x"]) cfg.maps.visualOnly)
|
||||
(mapAttrs (_key: processLegacyMap ["o"]) cfg.maps.operator)
|
||||
(mapAttrs (_key: processLegacyMap ["i" "c"]) cfg.maps.insertCommand)
|
||||
(mapAttrs (_key: processLegacyMap ["l"]) cfg.maps.lang)
|
||||
(mapAttrs (_key: processLegacyMap ["c"]) cfg.maps.command)
|
||||
]
|
||||
)
|
||||
(
|
||||
pipe cfg.maps
|
||||
[
|
||||
(mapAttrsToList (
|
||||
oldMode: keybinds:
|
||||
mapAttrsToList (
|
||||
key: bind:
|
||||
bind
|
||||
// {
|
||||
inherit key;
|
||||
mode = legacyMapModes.${oldMode};
|
||||
}
|
||||
)
|
||||
keybinds
|
||||
))
|
||||
flatten
|
||||
]
|
||||
)
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -31,6 +31,12 @@
|
|||
options =
|
||||
mapConfigOptions
|
||||
// {
|
||||
key = mkOption {
|
||||
type = str;
|
||||
description = ''
|
||||
Key that triggers this keybind.
|
||||
'';
|
||||
};
|
||||
mode = mkOption {
|
||||
type = either str (listOf str);
|
||||
description = ''
|
||||
|
@ -44,31 +50,36 @@
|
|||
};
|
||||
|
||||
# legacy stuff
|
||||
mapOption = submodule {
|
||||
legacyMapOption = submodule {
|
||||
options = mapConfigOptions;
|
||||
};
|
||||
|
||||
mapOptions = mode:
|
||||
mkOption {
|
||||
description = "Mappings for ${mode} mode";
|
||||
type = attrsOf mapOption;
|
||||
type = attrsOf legacyMapOption;
|
||||
default = {};
|
||||
};
|
||||
in {
|
||||
options.vim = {
|
||||
keymaps = mkOption {
|
||||
type = submodule {
|
||||
freeformType = attrsOf (listOf mapType);
|
||||
};
|
||||
type = listOf mapType;
|
||||
description = "Custom keybindings.";
|
||||
example = ''
|
||||
maps = {
|
||||
"<leader>m" = {
|
||||
vim.keymaps = [
|
||||
{
|
||||
key = "<leader>m";
|
||||
mode = "n";
|
||||
silent = true;
|
||||
action = "<cmd>make<CR>";
|
||||
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
|
||||
};
|
||||
action = ":make<CR>";
|
||||
}
|
||||
{
|
||||
key = "<leader>l";
|
||||
mode = ["n" "x"];
|
||||
silent = true;
|
||||
action = "<cmd>cnext<CR>";
|
||||
}
|
||||
];
|
||||
'';
|
||||
default = {};
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
inherit (builtins) map mapAttrs filter;
|
||||
inherit (lib.attrsets) mapAttrsToList filterAttrs;
|
||||
inherit (lib.strings) concatLines concatMapStringsSep optionalString;
|
||||
inherit (lib.trivial) showWarnings pipe;
|
||||
inherit (lib.trivial) showWarnings;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
|
@ -40,17 +40,9 @@ in {
|
|||
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 =
|
||||
pipe
|
||||
# attrsOf (listOf mapOption)
|
||||
cfg.keymaps
|
||||
[
|
||||
(mapAttrsToList (key: binds:
|
||||
concatLines (map (toLuaKeymap key) binds)))
|
||||
concatLines
|
||||
];
|
||||
maps = concatLines (map toLuaKeymap cfg.keymaps);
|
||||
|
||||
keymaps = maps;
|
||||
in {
|
||||
|
|
Loading…
Reference in a new issue