feat: Port mapped keymaps to library fn

This commit is contained in:
punkfairie 2024-11-25 18:58:53 -08:00
parent 19b11cd89e
commit 43ce08cb9c
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696

View file

@ -13,7 +13,7 @@
toLower toLower
; ;
inherit (lib.marleyos.keys) mkKeymap mkKeymapWithOpts; inherit (lib.marleyos.keys) mkKeymap mkKeymap' mkKeymapWithOpts;
inherit (helpers) mkRaw; inherit (helpers) mkRaw;
in { in {
globals = { globals = {
@ -22,45 +22,22 @@ in {
}; };
keymaps = keymaps =
#
# Disable Arrow Key Movement - - - - - - - - - - - - - - - - - - - - - - - - # Disable Arrow Key Movement - - - - - - - - - - - - - - - - - - - - - - - -
( (map (d: mkKeymap' ["i" "n"] d "<nop>") ["<Down>" "<Up>" "<Left>" "<Right>"])
map #
(d: {
mode = [
"i"
"n"
];
key = d;
action = "<nop>";
})
[
"<Down>"
"<Up>"
"<Left>"
"<Right>"
]
)
# Better Up/Down - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Better Up/Down - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (
mapAttrsToList mapAttrsToList
(d: k: { (d: k:
mode = [ mkKeymapWithOpts ["n" "x"] k "v:count == 0 ? 'g${k}' : '${k}'" d
"n" {expr = true;})
"x"
];
key = k;
action = "v:count == 0 ? 'g${k}' : '${k}'";
options = {
desc = d;
expr = true;
silent = true;
};
})
{ {
Down = "j"; Down = "j";
Up = "k"; Up = "k";
} }
) )
#
# Resize Windows - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Resize Windows - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (
mapAttrsToList mapAttrsToList
@ -70,14 +47,8 @@ in {
if (d == "Increase") if (d == "Increase")
then "+" then "+"
else "-"; else "-";
in { in
mode = ["n"]; mkKeymap ["n"] "<C-${k}>" "<cmd>resize ${s}4<cr>" "${d} Window Height"
key = "<C-${k}>";
action = "<cmd>resize ${s}4<cr>";
options = {
desc = "${d} Window Height";
};
}
) )
{ {
Up = "Increase"; Up = "Increase";
@ -86,21 +57,15 @@ in {
Right = "Increase"; Right = "Increase";
} }
) )
#
# Buffers - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Buffers - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (
mapAttrsToList mapAttrsToList (
(
k: d: let k: d: let
# previous -> Prev # previous -> Prev
prettyDir = (toUpper (substring 0 1 d)) + (substring 1 3 d); prettyDir = (toUpper (substring 0 1 d)) + (substring 1 3 d);
in { in
mode = ["n"]; mkKeymap ["n"] k "<cmd>b${d}<cr>" "${prettyDir} Buffer"
key = k;
action = "<cmd>b${d}<cr>";
options = {
desc = "${prettyDir} Buffer";
};
}
) )
{ {
"<S-h>" = "previous"; "<S-h>" = "previous";
@ -109,28 +74,29 @@ in {
"]b" = "next"; "]b" = "next";
} }
) )
++ [ ++ [(mkKeymap ["n"] "<leader>bD" "<cmd>bd<cr>" "Delete Buffer and Window")]
(mkKeymap ["n"] "<leader>bD" "<cmd>bd<cr>" "Delete Buffer and Window") #
]
# Clear Search/Diff Update/Redraw - - - - - - - - - - - - - - - - - - - - - # Clear Search/Diff Update/Redraw - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [
(mkKeymap [ (mkKeymap ["i" "n"] "<esc>" "<cmd>noh<cr><esc>" "Escape and Clear hlsearch")
"i"
"n"
] "<esc>" "<cmd>noh<cr><esc>" "Escape and Clear hlsearch")
( (
mkKeymap ["n"] "<leader>ur" "<cmd>nohlsearch<bar>diffupdate<bar>normal! <C-l><cr>" mkKeymap ["n"] "<leader>ur"
"<cmd>nohlsearch<bar>diffupdate<bar>normal! <C-l><cr>"
"Redraw / Clear hlsearch / Diff Update" "Redraw / Clear hlsearch / Diff Update"
) )
] ]
#
# Better n & N - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Better n & N - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (
mapCartesianProduct mapCartesianProduct (
(
{ {
m, m,
d, d,
}: let }: let
k =
if (d == "Next")
then "n"
else "N";
nn = nn =
if (d == "Next") if (d == "Next")
then "Nn" then "Nn"
@ -139,103 +105,63 @@ in {
if (m == "n") if (m == "n")
then ".'zv'" then ".'zv'"
else ""; else "";
in { in
mode = [m]; mkKeymapWithOpts [m] k "'${nn}'[v:searchforward]${zv}"
key = "${d} Search Result" {expr = true;}
if (d == "Next")
then "n"
else "N";
action = "'${nn}'[v:searchforward]${zv}";
options = {
desc = "${d} Search Result";
expr = true;
};
}
) )
{ {
m = [ m = ["n" "x" "o"];
"n" d = ["Next" "Prev"];
"x"
"o"
];
d = [
"Next"
"Prev"
];
} }
) )
#
# Undo Break-Points - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Undo Break-Points - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (map (c: mkKeymap' ["i"] c "${c}<c-g>u") ["," "." ";"])
map #
(c: {
mode = ["i"];
key = c;
action = "${c}<c-g>u";
})
[
","
"."
";"
]
)
# Search Docs (keywordprog) - - - - - - - - - - - - - - - - - - - - - - - - # Search Docs (keywordprog) - - - - - - - - - - - - - - - - - - - - - - - -
# https://til.codeinthehole.com/posts/about-how-to-use-keywordprg-effectively/ # https://til.codeinthehole.com/posts/about-how-to-use-keywordprg-effectively/
++ [(mkKeymap ["n"] "<leader>K" "<cmd>norm! K<cr>" "Search <keywordprog> for word")] ++ [
(mkKeymap ["n"] "<leader>K" "<cmd>norm! K<cr>"
"Search <keywordprog> for word")
]
#
# Better Indenting - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Better Indenting - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (map (c: mkKeymap' ["v"] c "${c}gv") ["<" ">"])
map #
(c: {
mode = ["v"];
key = c;
action = "${c}gv";
})
[
"<"
">"
]
)
# Commenting - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Commenting - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (
mapAttrsToList mapAttrsToList (
(k: d: { k: d:
mode = ["n"]; mkKeymap ["n"] "gc${k}"
key = "gc${k}"; "${k}<esc>Vcx<esc><cmd>normal gcc<cr>fxa<bs>" "Add Comment ${d}"
action = "${k}<esc>Vcx<esc><cmd>normal gcc<cr>fxa<bs>"; )
options = {
desc = "Add Comment ${d}";
};
})
{ {
o = "Below"; o = "Below";
O = "Above"; O = "Above";
} }
) )
#
# New File - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # New File - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [(mkKeymap ["n"] "<leader>fn" "<cmd>enew<cr>" "New File")] ++ [(mkKeymap ["n"] "<leader>fn" "<cmd>enew<cr>" "New File")]
#
# Locations/Quickfixes - - - - - - - - - - - - - - - - - - - - - - - - - - - # Locations/Quickfixes - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [
(mkKeymap ["n"] "<leader>xl" "<cmd>lopen<cr>" "Location List") (mkKeymap ["n"] "<leader>xl" "<cmd>lopen<cr>" "Location List")
(mkKeymap ["n"] "<leader>xq" "<cmd>copen<cr>" "Quickfix list") (mkKeymap ["n"] "<leader>xq" "<cmd>copen<cr>" "Quickfix list")
] ]
++ ( ++ (
mapAttrsToList mapAttrsToList (
(
k: d: let k: d: let
cmd = substring 0 4 (toLower d); cmd = substring 0 4 (toLower d);
in { in
mode = ["n"]; mkKeymap ["n"] "${k}q" "<cmd>c${cmd}<cr>" "${d} Quickfix"
key = "${k}q";
action = "<cmd>c${cmd}<cr>";
options = {
desc = "${d} Quickfix";
};
}
) )
{ {
"[" = "Previous"; "[" = "Previous";
"]" = "Next"; "]" = "Next";
} }
) )
#
# Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [
(mkKeymap ["n"] "<leader>cd" ( (mkKeymap ["n"] "<leader>cd" (
@ -245,12 +171,17 @@ in {
) "Line Diagnostics") ) "Line Diagnostics")
] ]
++ ( ++ (
mapCartesianProduct mapCartesianProduct (
(
{ {
dir, dir,
key, key,
}: let }: let
kmap = "${
if (dir == "Next")
then "]"
else "["
}${key}";
sevs = { sevs = {
d = { d = {
key = "nil"; key = "nil";
@ -268,37 +199,25 @@ in {
cmd = toLower dir; cmd = toLower dir;
sev = sevs."${key}".key; sev = sevs."${key}".key;
in { in
mode = ["n"]; mkKeymap ["n"] kmap
key = "${ (mkRaw
if (dir == "Next")
then "]"
else "["
}${key}";
action.__raw =
# lua # lua
"function() vim.diagnostic.goto_${cmd}({ severity = ${sev} }) end"; "function() vim.diagnostic.goto_${cmd}({ severity = ${sev} }) end")
options = { "${dir} ${sevs."${key}".desc}"
desc = "${dir} ${sevs."${key}".desc}";
};
}
) )
{ {
dir = [ dir = ["Next" "Prev"];
"Next" key = ["d" "e" "w"];
"Prev"
];
key = [
"d"
"e"
"w"
];
} }
) )
#
# Quit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Quit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [(mkKeymap ["n"] "<leader>qq" "<cmd>qa<cr>" "Quit All")] ++ [(mkKeymap ["n"] "<leader>qq" "<cmd>qa<cr>" "Quit All")]
#
# Inspect - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Inspect - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [(mkKeymap ["n"] "<leader>ui" (mkRaw "vim.show_pos") "Inspect Position")] ++ [(mkKeymap ["n"] "<leader>ui" (mkRaw "vim.show_pos") "Inspect Position")]
#
# Window Management - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Window Management - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [
(mkKeymapWithOpts ["n"] "<leader>w" "<C-w>" "Windows" {remap = true;}) (mkKeymapWithOpts ["n"] "<leader>w" "<C-w>" "Windows" {remap = true;})
@ -306,20 +225,18 @@ in {
(mkKeymapWithOpts ["n"] "<leader>|" "<C-w>v" "Split Window Right" {remap = true;}) (mkKeymapWithOpts ["n"] "<leader>|" "<C-w>v" "Split Window Right" {remap = true;})
(mkKeymapWithOpts ["n"] "<leader>wd" "<C-w>c" "Delete Window" {remap = true;}) (mkKeymapWithOpts ["n"] "<leader>wd" "<C-w>c" "Delete Window" {remap = true;})
] ]
#
# Tab Management - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Tab Management - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (
mapAttrsToList mapAttrsToList (
(k: a: { k: a: let
mode = ["n"];
key = "<leader><tab>${k}";
action = "<cmd>tab${toLower a}<cr>";
options = {
desc = desc =
if (a == "Only") if (a == "Only")
then "Close Other Tabs" then "Close Other Tabs"
else "${a} Tab"; else "${a} Tab";
}; in
}) mkKeymap ["n"] "<leader><tab>${k}" "<cmd>tab${toLower a}<cr>" desc
)
{ {
l = "Last"; l = "Last";
o = "Only"; o = "Only";