mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-30 08:36:46 +00:00
Compare commits
38 commits
51035c5468
...
f905acaf05
Author | SHA1 | Date | |
---|---|---|---|
|
f905acaf05 | ||
|
c5c7d46e35 | ||
|
c0bfe6bb38 | ||
|
5136fc4bd1 | ||
|
2e2a34f9ac | ||
|
97aa39bc02 | ||
|
b7d9febe25 | ||
|
767407a7d4 | ||
|
eeb54209e2 | ||
|
aeabcb80e0 | ||
|
645574073a | ||
|
afec78de26 | ||
|
6497644e6d | ||
|
290cfebec5 | ||
|
346950ad7a | ||
|
ed88e796a6 | ||
|
acbc2ecfa0 | ||
|
d5bc0ce4f9 | ||
|
7350769edf | ||
|
74bc4f843d | ||
|
d5b6923f5a | ||
|
86bb6fffdf | ||
|
bf858feb11 | ||
|
5708487de7 | ||
|
140a2ed660 | ||
|
6feafdc292 | ||
|
2927800175 | ||
|
e6c15ed881 | ||
|
dc79db2e89 | ||
|
a0006ca486 | ||
|
de82d9b2c8 | ||
|
2d797ead5d | ||
|
0fac19afee | ||
|
ccc871047c | ||
|
d013475282 | ||
|
57afef8321 | ||
|
b89c311d95 | ||
|
7b00ab4fa3 |
3 changed files with 44 additions and 66 deletions
|
@ -4,74 +4,55 @@
|
|||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (lib.trivial) pipe;
|
||||
inherit (lib.attrsets) mapAttrsToList;
|
||||
inherit (lib.lists) flatten;
|
||||
inherit (builtins) mapAttrs;
|
||||
|
||||
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"];
|
||||
};
|
||||
processLegacyMap = modes: legacyMap: [(legacyMap // {mode = modes;})];
|
||||
|
||||
cfg = config.vim;
|
||||
in {
|
||||
config = {
|
||||
vim.keymaps = mkMerge [
|
||||
(
|
||||
mkIf cfg.disableArrows [
|
||||
(mkIf cfg.disableArrows {
|
||||
"<up>" = [
|
||||
{
|
||||
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;
|
||||
}
|
||||
]
|
||||
)
|
||||
(
|
||||
pipe cfg.maps
|
||||
[
|
||||
(mapAttrsToList (
|
||||
oldMode: keybinds:
|
||||
mapAttrsToList (
|
||||
key: bind:
|
||||
bind
|
||||
// {
|
||||
inherit key;
|
||||
mode = legacyMapModes.${oldMode};
|
||||
}
|
||||
)
|
||||
keybinds
|
||||
))
|
||||
flatten
|
||||
]
|
||||
)
|
||||
];
|
||||
})
|
||||
(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)
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -31,12 +31,6 @@
|
|||
options =
|
||||
mapConfigOptions
|
||||
// {
|
||||
key = mkOption {
|
||||
type = str;
|
||||
description = ''
|
||||
Key that triggers this keybind.
|
||||
'';
|
||||
};
|
||||
mode = mkOption {
|
||||
type = either str (listOf str);
|
||||
description = ''
|
||||
|
@ -50,36 +44,31 @@
|
|||
};
|
||||
|
||||
# legacy stuff
|
||||
legacyMapOption = submodule {
|
||||
mapOption = submodule {
|
||||
options = mapConfigOptions;
|
||||
};
|
||||
|
||||
mapOptions = mode:
|
||||
mkOption {
|
||||
description = "Mappings for ${mode} mode";
|
||||
type = attrsOf legacyMapOption;
|
||||
type = attrsOf mapOption;
|
||||
default = {};
|
||||
};
|
||||
in {
|
||||
options.vim = {
|
||||
keymaps = mkOption {
|
||||
type = listOf mapType;
|
||||
type = submodule {
|
||||
freeformType = attrsOf (listOf mapType);
|
||||
};
|
||||
description = "Custom keybindings.";
|
||||
example = ''
|
||||
vim.keymaps = [
|
||||
{
|
||||
key = "<leader>m";
|
||||
maps = {
|
||||
"<leader>m" = {
|
||||
mode = "n";
|
||||
silent = true;
|
||||
action = ":make<CR>";
|
||||
}
|
||||
{
|
||||
key = "<leader>l";
|
||||
mode = ["n" "x"];
|
||||
silent = true;
|
||||
action = "<cmd>cnext<CR>";
|
||||
}
|
||||
];
|
||||
action = "<cmd>make<CR>";
|
||||
}; # Same as nnoremap <leader>m <silent> <cmd>make<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;
|
||||
inherit (lib.trivial) showWarnings pipe;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
inherit (lib.nvim.dag) entryAfter mkLuarcSection resolveDag entryAnywhere;
|
||||
inherit (lib.nvim.lua) toLuaObject;
|
||||
|
@ -40,9 +40,17 @@ in {
|
|||
inherit (keymap) desc silent nowait script expr unique noremap;
|
||||
};
|
||||
|
||||
toLuaKeymap = bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject bind.key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";
|
||||
toLuaKeymap = key: bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";
|
||||
|
||||
maps = concatLines (map toLuaKeymap cfg.keymaps);
|
||||
maps =
|
||||
pipe
|
||||
# attrsOf (listOf mapOption)
|
||||
cfg.keymaps
|
||||
[
|
||||
(mapAttrsToList (key: binds:
|
||||
concatLines (map (toLuaKeymap key) binds)))
|
||||
concatLines
|
||||
];
|
||||
|
||||
keymaps = maps;
|
||||
in {
|
||||
|
|
Loading…
Reference in a new issue