mirror of
https://github.com/NotAShelf/nvf.git
synced 2024-11-22 21:30:51 +00:00
Compare commits
40 commits
b46534291e
...
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 | ||
|
fd4ddbdd39 | ||
|
b8c8dc2484 |
3 changed files with 79 additions and 74 deletions
|
@ -3,32 +3,56 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (builtins) mapAttrs;
|
||||
|
||||
processLegacyMap = modes: legacyMap: [(legacyMap // {mode = modes;})];
|
||||
|
||||
cfg = config.vim;
|
||||
in {
|
||||
config = {
|
||||
vim.maps = mkIf cfg.disableArrows {
|
||||
"<up>" = {
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
};
|
||||
"<down>" = {
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
};
|
||||
"<left>" = {
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
};
|
||||
"<right>" = {
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
};
|
||||
};
|
||||
vim.keymaps = mkMerge [
|
||||
(mkIf cfg.disableArrows {
|
||||
"<up>" = [
|
||||
{
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
}
|
||||
];
|
||||
"<down>" = [
|
||||
{
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
}
|
||||
];
|
||||
"<left>" = [
|
||||
{
|
||||
mode = ["n" "i"];
|
||||
action = "<nop>";
|
||||
noremap = false;
|
||||
}
|
||||
];
|
||||
"<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)
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
See `:help map-modes` for a list of modes.
|
||||
'';
|
||||
example = ''"nvc" for normal, visual and command mode'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -55,25 +56,10 @@
|
|||
};
|
||||
in {
|
||||
options.vim = {
|
||||
maps = mkOption {
|
||||
keymaps = mkOption {
|
||||
type = submodule {
|
||||
freeformType = attrsOf mapType;
|
||||
options = {
|
||||
normal = mapOptions "normal";
|
||||
insert = mapOptions "insert";
|
||||
select = mapOptions "select";
|
||||
visual = mapOptions "visual and select";
|
||||
terminal = mapOptions "terminal";
|
||||
normalVisualOp = mapOptions "normal, visual, select and operator-pending (same as plain 'map')";
|
||||
|
||||
visualOnly = mapOptions "visual only";
|
||||
operator = mapOptions "operator-pending";
|
||||
insertCommand = mapOptions "insert and command-line";
|
||||
lang = mapOptions "insert, command-line and lang-arg";
|
||||
command = mapOptions "command-line";
|
||||
};
|
||||
freeformType = attrsOf (listOf mapType);
|
||||
};
|
||||
default = {};
|
||||
description = "Custom keybindings.";
|
||||
example = ''
|
||||
maps = {
|
||||
|
@ -84,6 +70,22 @@ in {
|
|||
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
|
||||
};
|
||||
'';
|
||||
default = {};
|
||||
};
|
||||
|
||||
maps = {
|
||||
normal = mapOptions "normal";
|
||||
insert = mapOptions "insert";
|
||||
select = mapOptions "select";
|
||||
visual = mapOptions "visual and select";
|
||||
terminal = mapOptions "terminal";
|
||||
normalVisualOp = mapOptions "normal, visual, select and operator-pending (same as plain 'map')";
|
||||
|
||||
visualOnly = mapOptions "visual only";
|
||||
operator = mapOptions "operator-pending";
|
||||
insertCommand = mapOptions "insert and command-line";
|
||||
lang = mapOptions "insert, command-line and lang-arg";
|
||||
command = mapOptions "command-line";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) map mapAttrs filter removeAttrs attrNames;
|
||||
inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList;
|
||||
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,40 +40,19 @@ in {
|
|||
inherit (keymap) desc silent nowait script expr unique noremap;
|
||||
};
|
||||
|
||||
toLuaKeymap = {
|
||||
name,
|
||||
value,
|
||||
}: "vim.keymap.set(${toLuaObject value.mode}, ${toLuaObject name}, ${toLuaObject (getAction value)}, ${toLuaObject (getOpts value)})";
|
||||
|
||||
namedModes = {
|
||||
"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"];
|
||||
};
|
||||
toLuaKeymap = key: bind: "vim.keymap.set(${toLuaObject bind.mode}, ${toLuaObject key}, ${toLuaObject (getAction bind)}, ${toLuaObject (getOpts bind)})";
|
||||
|
||||
maps =
|
||||
removeAttrs cfg.maps (attrNames namedModes)
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.normal;}) cfg.maps.normal
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.insert;}) cfg.maps.insert
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.select;}) cfg.maps.select
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.visual;}) cfg.maps.visual
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.terminal;}) cfg.maps.terminal
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.normalVisualOp;}) cfg.maps.normalVisualOp
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.visualOnly;}) cfg.maps.visualOnly
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.operator;}) cfg.maps.operator
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.insertCommand;}) cfg.maps.insertCommand
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.lang;}) cfg.maps.lang
|
||||
// mapAttrs (_: legacyMap: legacyMap // {mode = namedModes.command;}) cfg.maps.command;
|
||||
pipe
|
||||
# attrsOf (listOf mapOption)
|
||||
cfg.keymaps
|
||||
[
|
||||
(mapAttrsToList (key: binds:
|
||||
concatLines (map (toLuaKeymap key) binds)))
|
||||
concatLines
|
||||
];
|
||||
|
||||
keymaps = concatLines (map toLuaKeymap (attrsToList (filterNonNull maps)));
|
||||
keymaps = maps;
|
||||
in {
|
||||
vim = {
|
||||
luaConfigRC = {
|
||||
|
|
Loading…
Reference in a new issue