mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-02-12 20:13:19 +00:00
Compare commits
38 commits
f905acaf05
...
b46534291e
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b46534291e | ||
![]() |
fbc9a750a9 | ||
![]() |
0f1c384d23 | ||
![]() |
c331e3303e | ||
![]() |
745d539732 | ||
![]() |
4dcce23410 | ||
![]() |
29f9e3f168 | ||
![]() |
60b0c630a7 | ||
![]() |
6b94991888 | ||
![]() |
ff214eb491 | ||
![]() |
61dc161ef7 | ||
![]() |
c80f303b0f | ||
![]() |
a6568e64dd | ||
![]() |
98bfd74de3 | ||
![]() |
7260efac66 | ||
![]() |
be6e41e876 | ||
![]() |
8195ad5cc9 | ||
![]() |
ad5b928830 | ||
![]() |
3fbef8cdb4 | ||
![]() |
fc63d2e0a1 | ||
![]() |
980c80f0b8 | ||
![]() |
320d05aff2 | ||
![]() |
1b661bacfd | ||
![]() |
3763d71124 | ||
![]() |
1e83f6f50b | ||
![]() |
e07ff4029b | ||
![]() |
dee9fa0d61 | ||
![]() |
7aef3392fd | ||
![]() |
4a8c83130d | ||
![]() |
8a0ffcb69f | ||
![]() |
8f92dd2dc1 | ||
![]() |
0d452bcaf7 | ||
![]() |
44681a4cb5 | ||
![]() |
b1a1aaba46 | ||
![]() |
b409800b2f | ||
![]() |
ad8ce463f1 | ||
![]() |
6d654ce4cd | ||
![]() |
202ea7570d |
3 changed files with 74 additions and 79 deletions
|
@ -3,56 +3,32 @@
|
|||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.modules) mkIf mkMerge;
|
||||
inherit (builtins) mapAttrs;
|
||||
|
||||
processLegacyMap = modes: legacyMap: [(legacyMap // {mode = modes;})];
|
||||
inherit (lib.modules) mkIf;
|
||||
|
||||
cfg = config.vim;
|
||||
in {
|
||||
config = {
|
||||
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)
|
||||
];
|
||||
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;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
|
||||
See `:help map-modes` for a list of modes.
|
||||
'';
|
||||
example = ''"nvc" for normal, visual and command mode'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -56,10 +55,25 @@
|
|||
};
|
||||
in {
|
||||
options.vim = {
|
||||
keymaps = mkOption {
|
||||
maps = mkOption {
|
||||
type = submodule {
|
||||
freeformType = attrsOf (listOf mapType);
|
||||
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";
|
||||
};
|
||||
};
|
||||
default = {};
|
||||
description = "Custom keybindings.";
|
||||
example = ''
|
||||
maps = {
|
||||
|
@ -70,22 +84,6 @@ 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;
|
||||
inherit (lib.attrsets) mapAttrsToList filterAttrs;
|
||||
inherit (builtins) map mapAttrs filter removeAttrs attrNames;
|
||||
inherit (lib.attrsets) mapAttrsToList filterAttrs attrsToList;
|
||||
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,19 +40,40 @@ 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 = {
|
||||
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"];
|
||||
};
|
||||
|
||||
maps =
|
||||
pipe
|
||||
# attrsOf (listOf mapOption)
|
||||
cfg.keymaps
|
||||
[
|
||||
(mapAttrsToList (key: binds:
|
||||
concatLines (map (toLuaKeymap key) binds)))
|
||||
concatLines
|
||||
];
|
||||
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;
|
||||
|
||||
keymaps = maps;
|
||||
keymaps = concatLines (map toLuaKeymap (attrsToList (filterNonNull maps)));
|
||||
in {
|
||||
vim = {
|
||||
luaConfigRC = {
|
||||
|
|
Loading…
Add table
Reference in a new issue