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