Compare commits

..

40 commits

Author SHA1 Message Date
Ching Pei Yang
f905acaf05
Merge c5c7d46e35 into e40cce5653 2024-08-18 13:07:58 +00:00
Ching Pei Yang
c5c7d46e35 flake: update lzn-auto-require 2024-08-18 15:07:52 +02:00
Ching Pei Yang
c0bfe6bb38 lz.n: add missing PluginSpec options 2024-08-18 15:07:52 +02:00
Ching Pei Yang
5136fc4bd1 add TODO 2024-08-18 15:07:52 +02:00
Ching Pei Yang
2e2a34f9ac lib: allow luaInline in lz.n map action 2024-08-18 15:07:52 +02:00
Ching Pei Yang
97aa39bc02 flake: update lzn-auto-require 2024-08-18 15:07:52 +02:00
Ching Pei Yang
b7d9febe25 fixup! wrapper: use lzn-auto-require loader 2024-08-18 15:07:52 +02:00
Ching Pei Yang
767407a7d4 lib: add mkSetLuaBinding 2024-08-18 15:07:52 +02:00
Ching Pei Yang
eeb54209e2 wrapper: use lzn-auto-require loader 2024-08-18 15:07:52 +02:00
Ching Pei Yang
aeabcb80e0 flake: add plugin lzn-auto-require 2024-08-18 15:07:52 +02:00
Ching Pei Yang
645574073a lz.n: generate less code 2024-08-18 15:07:52 +02:00
Ching Pei Yang
afec78de26 lz.n: wrap lua code in function 2024-08-18 15:07:52 +02:00
Ching Pei Yang
6497644e6d lib: add mkLznBinding 2024-08-18 15:07:52 +02:00
Ching Pei Yang
290cfebec5 nvim-tree: load nvim-tree if openOnSetup 2024-08-18 15:07:52 +02:00
Ching Pei Yang
346950ad7a nvim-tree: move to lz.n keymaps 2024-08-18 15:07:52 +02:00
Ching Pei Yang
ed88e796a6 lib: add mkLznBinding 2024-08-18 15:07:52 +02:00
Ching Pei Yang
acbc2ecfa0 lib: change lz.n spec "inlineLua" types to str 2024-08-18 15:07:52 +02:00
Ching Pei Yang
d5bc0ce4f9 lz.n: missing type check 2024-08-18 15:07:52 +02:00
Ching Pei Yang
7350769edf lib: add lznKeySpec example 2024-08-18 15:07:52 +02:00
Ching Pei Yang
74bc4f843d lz.n: process key maps 2024-08-18 15:07:52 +02:00
Ching Pei Yang
d5b6923f5a remove unused 2024-08-18 15:07:52 +02:00
Pei Yang Ching
86bb6fffdf lib: fix lz.n map type 2024-08-18 15:07:52 +02:00
Ching Pei Yang
bf858feb11 lib: add lz.n KeySpec 2024-08-18 15:07:52 +02:00
Pei Yang Ching
5708487de7 nvim-tree: use lazy 2024-08-18 15:07:52 +02:00
Pei Yang Ching
140a2ed660 lazy: add setupOpts support 2024-08-18 15:07:52 +02:00
Pei Yang Ching
6feafdc292 fix: broken optPlugins 2024-08-18 15:07:52 +02:00
Pei Yang Ching
2927800175 switch to other hacky array-table syntax 2024-08-18 15:07:52 +02:00
Pei Yang Ching
e6c15ed881 wrap lazy init code in function 2024-08-18 15:07:52 +02:00
Ching Pei Yang
dc79db2e89 flake: update lz.n 2024-08-18 15:07:52 +02:00
Ching Pei Yang
a0006ca486 lib: add lznPluginTableType 2024-08-18 15:07:52 +02:00
Ching Pei Yang
de82d9b2c8 lib: export lznPluginType 2024-08-18 15:07:52 +02:00
Ching Pei Yang
2d797ead5d lz.n: load lz.n 2024-08-18 15:07:52 +02:00
Ching Pei Yang
0fac19afee lz.n: add basic lazy.plugins option 2024-08-18 15:07:52 +02:00
Pei Yang Ching
ccc871047c lib: add basic lz.n plugin spec type 2024-08-18 15:07:52 +02:00
Pei Yang Ching
d013475282 add lazy module skeleton 2024-08-18 15:07:52 +02:00
Pei Yang Ching
57afef8321 flake: add lz.n plugin 2024-08-18 15:07:52 +02:00
Pei Yang Ching
b89c311d95 maps: fix missing description 2024-08-18 15:07:52 +02:00
Ching Pei Yang
7b00ab4fa3 remove unused 2024-08-18 15:07:52 +02:00
Pei Yang Ching
fd4ddbdd39 maps: fix bad mode names 2024-08-18 15:05:11 +02:00
Pei Yang Ching
b8c8dc2484 maps: allow same key on multiple mode 2024-08-18 14:43:38 +02:00
3 changed files with 79 additions and 74 deletions

View file

@ -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>" = {
vim.keymaps = mkMerge [
(mkIf cfg.disableArrows {
"<up>" = [
{
mode = ["n" "i"];
action = "<nop>";
noremap = false;
};
"<down>" = {
}
];
"<down>" = [
{
mode = ["n" "i"];
action = "<nop>";
noremap = false;
};
"<left>" = {
}
];
"<left>" = [
{
mode = ["n" "i"];
action = "<nop>";
noremap = false;
};
"<right>" = {
}
];
"<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)
];
};
}

View file

@ -38,6 +38,7 @@
See `:help map-modes` for a list of modes.
'';
example = ''"nvc" for normal, visual and command mode'';
};
};
};
@ -55,10 +56,24 @@
};
in {
options.vim = {
maps = mkOption {
keymaps = mkOption {
type = submodule {
freeformType = attrsOf mapType;
options = {
freeformType = attrsOf (listOf mapType);
};
description = "Custom keybindings.";
example = ''
maps = {
"<leader>m" = {
mode = "n";
silent = true;
action = "<cmd>make<CR>";
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
};
'';
default = {};
};
maps = {
normal = mapOptions "normal";
insert = mapOptions "insert";
select = mapOptions "select";
@ -73,17 +88,4 @@ in {
command = mapOptions "command-line";
};
};
default = {};
description = "Custom keybindings.";
example = ''
maps = {
"<leader>m" = {
mode = "n";
silent = true;
action = "<cmd>make<CR>";
}; # Same as nnoremap <leader>m <silent> <cmd>make<CR>
};
'';
};
};
}

View file

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