Compare commits

..

38 commits

Author SHA1 Message Date
Ching Pei Yang
b46534291e
Merge fbc9a750a9 into e40cce5653 2024-08-17 22:23:21 +00:00
Ching Pei Yang
fbc9a750a9 flake: update lzn-auto-require 2024-08-18 00:23:06 +02:00
Ching Pei Yang
0f1c384d23 lz.n: add missing PluginSpec options 2024-08-18 00:23:06 +02:00
Ching Pei Yang
c331e3303e add TODO 2024-08-17 13:03:54 +02:00
Ching Pei Yang
745d539732 lib: allow luaInline in lz.n map action 2024-08-17 13:03:54 +02:00
Ching Pei Yang
4dcce23410 flake: update lzn-auto-require 2024-08-17 13:03:54 +02:00
Ching Pei Yang
29f9e3f168 fixup! wrapper: use lzn-auto-require loader 2024-08-17 13:03:54 +02:00
Ching Pei Yang
60b0c630a7 lib: add mkSetLuaBinding 2024-08-17 13:03:54 +02:00
Ching Pei Yang
6b94991888 wrapper: use lzn-auto-require loader 2024-08-17 13:03:54 +02:00
Ching Pei Yang
ff214eb491 flake: add plugin lzn-auto-require 2024-08-17 13:03:54 +02:00
Ching Pei Yang
61dc161ef7 lz.n: generate less code 2024-08-17 13:03:54 +02:00
Ching Pei Yang
c80f303b0f lz.n: wrap lua code in function 2024-08-17 13:03:54 +02:00
Ching Pei Yang
a6568e64dd lib: add mkLznBinding 2024-08-17 13:03:54 +02:00
Ching Pei Yang
98bfd74de3 nvim-tree: load nvim-tree if openOnSetup 2024-08-17 13:03:54 +02:00
Ching Pei Yang
7260efac66 nvim-tree: move to lz.n keymaps 2024-08-17 13:03:54 +02:00
Ching Pei Yang
be6e41e876 lib: add mkLznBinding 2024-08-17 13:03:54 +02:00
Ching Pei Yang
8195ad5cc9 lib: change lz.n spec "inlineLua" types to str 2024-08-17 13:03:54 +02:00
Ching Pei Yang
ad5b928830 lz.n: missing type check 2024-08-17 13:03:54 +02:00
Ching Pei Yang
3fbef8cdb4 lib: add lznKeySpec example 2024-08-17 13:03:54 +02:00
Ching Pei Yang
fc63d2e0a1 lz.n: process key maps 2024-08-17 13:03:54 +02:00
Ching Pei Yang
980c80f0b8 remove unused 2024-08-17 13:03:54 +02:00
Pei Yang Ching
320d05aff2 lib: fix lz.n map type 2024-08-17 13:03:54 +02:00
Ching Pei Yang
1b661bacfd lib: add lz.n KeySpec 2024-08-17 13:03:54 +02:00
Pei Yang Ching
3763d71124 nvim-tree: use lazy 2024-08-17 13:03:54 +02:00
Pei Yang Ching
1e83f6f50b lazy: add setupOpts support 2024-08-17 13:03:54 +02:00
Pei Yang Ching
e07ff4029b fix: broken optPlugins 2024-08-17 13:03:54 +02:00
Pei Yang Ching
dee9fa0d61 switch to other hacky array-table syntax 2024-08-17 13:03:54 +02:00
Pei Yang Ching
7aef3392fd wrap lazy init code in function 2024-08-17 13:03:54 +02:00
Ching Pei Yang
4a8c83130d flake: update lz.n 2024-08-17 13:03:54 +02:00
Ching Pei Yang
8a0ffcb69f lib: add lznPluginTableType 2024-08-17 13:03:54 +02:00
Ching Pei Yang
8f92dd2dc1 lib: export lznPluginType 2024-08-17 13:03:54 +02:00
Ching Pei Yang
0d452bcaf7 lz.n: load lz.n 2024-08-17 13:03:54 +02:00
Ching Pei Yang
44681a4cb5 lz.n: add basic lazy.plugins option 2024-08-17 13:03:54 +02:00
Pei Yang Ching
b1a1aaba46 lib: add basic lz.n plugin spec type 2024-08-17 13:03:54 +02:00
Pei Yang Ching
b409800b2f add lazy module skeleton 2024-08-17 13:03:54 +02:00
Pei Yang Ching
ad8ce463f1 flake: add lz.n plugin 2024-08-17 13:03:54 +02:00
Pei Yang Ching
6d654ce4cd maps: fix missing description 2024-08-17 13:02:25 +02:00
Ching Pei Yang
202ea7570d remove unused 2024-08-17 12:55:55 +02:00
3 changed files with 74 additions and 79 deletions

View file

@ -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;
};
};
};
}

View file

@ -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";
};
};
}

View file

@ -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 = {