marleyvim/modules/nixvim/keymaps/default.nix

250 lines
6.5 KiB
Nix
Raw Normal View History

{
lib,
helpers,
...
}: let
2024-11-25 17:47:14 -08:00
inherit
(lib)
2024-11-24 19:46:48 -08:00
map
mapAttrsToList
toUpper
substring
mapCartesianProduct
toLower
;
2024-11-25 19:05:18 -08:00
inherit (lib.marleyos) keys;
inherit (helpers) mkRaw;
2024-11-25 17:47:14 -08:00
in {
2024-11-24 19:46:48 -08:00
globals = {
mapleader = " ";
maplocalleader = "\\";
};
keymaps =
#
2024-11-24 19:46:48 -08:00
# Disable Arrow Key Movement - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 19:05:18 -08:00
(map (d: keys.mk' ["i" "n"] d "<nop>") ["<Down>" "<Up>" "<Left>" "<Right>"])
#
2024-11-24 19:46:48 -08:00
# Better Up/Down - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 17:47:14 -08:00
++ (
mapAttrsToList
(d: k:
2024-11-25 19:05:18 -08:00
keys.mkWithOpts ["n" "x"] k "v:count == 0 ? 'g${k}' : '${k}'" d
{expr = true;})
2024-11-24 19:46:48 -08:00
{
Down = "j";
Up = "k";
}
)
#
2024-11-24 19:46:48 -08:00
# Resize Windows - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 17:47:14 -08:00
++ (
mapAttrsToList
2024-11-24 19:46:48 -08:00
(
2024-11-25 17:47:14 -08:00
k: d: let
s =
if (d == "Increase")
then "+"
else "-";
in
2024-11-25 19:05:18 -08:00
keys.mk ["n"] "<C-${k}>" "<cmd>resize ${s}4<cr>" "${d} Window Height"
2024-11-24 19:46:48 -08:00
)
{
Up = "Increase";
Down = "Decrease";
Left = "Decrease";
Right = "Increase";
}
)
#
2024-11-24 19:46:48 -08:00
# Buffers - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 17:47:14 -08:00
++ (
mapAttrsToList (
2024-11-25 17:47:14 -08:00
k: d: let
2024-11-24 19:46:48 -08:00
# previous -> Prev
prettyDir = (toUpper (substring 0 1 d)) + (substring 1 3 d);
in
2024-11-25 19:05:18 -08:00
keys.mk ["n"] k "<cmd>b${d}<cr>" "${prettyDir} Buffer"
2024-11-24 19:46:48 -08:00
)
{
"<S-h>" = "previous";
"<S-l>" = "next";
"[b" = "previous";
"]b" = "next";
}
)
2024-11-25 19:05:18 -08:00
++ [(keys.mk ["n"] "<leader>bD" "<cmd>bd<cr>" "Delete Buffer and Window")]
#
2024-11-24 19:46:48 -08:00
# Clear Search/Diff Update/Redraw - - - - - - - - - - - - - - - - - - - - -
++ [
2024-11-25 19:05:18 -08:00
(keys.mk ["i" "n"] "<esc>" "<cmd>noh<cr><esc>" "Escape and Clear hlsearch")
(
2024-11-25 19:05:18 -08:00
keys.mk ["n"] "<leader>ur"
"<cmd>nohlsearch<bar>diffupdate<bar>normal! <C-l><cr>"
"Redraw / Clear hlsearch / Diff Update"
)
2024-11-24 19:46:48 -08:00
]
#
2024-11-24 19:46:48 -08:00
# Better n & N - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 17:47:14 -08:00
++ (
mapCartesianProduct (
2024-11-24 19:46:48 -08:00
{
2024-11-25 17:47:14 -08:00
m,
d,
}: let
k =
if (d == "Next")
then "n"
else "N";
2024-11-25 17:47:14 -08:00
nn =
if (d == "Next")
then "Nn"
else "nN";
zv =
if (m == "n")
then ".'zv'"
else "";
in
2024-11-25 19:05:18 -08:00
keys.mkWithOpts [m] k "'${nn}'[v:searchforward]${zv}"
"${d} Search Result" {expr = true;}
2024-11-24 19:46:48 -08:00
)
{
m = ["n" "x" "o"];
d = ["Next" "Prev"];
2024-11-24 19:46:48 -08:00
}
)
#
2024-11-24 19:46:48 -08:00
# Undo Break-Points - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 19:05:18 -08:00
++ (map (c: keys.mk' ["i"] c "${c}<c-g>u") ["," "." ";"])
#
2024-11-24 19:46:48 -08:00
# Search Docs (keywordprog) - - - - - - - - - - - - - - - - - - - - - - - -
# https://til.codeinthehole.com/posts/about-how-to-use-keywordprg-effectively/
2024-11-25 19:05:18 -08:00
++ [(keys.mk ["n"] "<leader>K" "<cmd>norm! K<cr>" "Search <keywordprog> for word")]
#
2024-11-24 19:46:48 -08:00
# Better Indenting - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 19:05:18 -08:00
++ (map (c: keys.mk' ["v"] c "${c}gv") ["<" ">"])
#
2024-11-24 19:46:48 -08:00
# Commenting - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 17:47:14 -08:00
++ (
mapAttrsToList (
k: d:
2024-11-25 19:05:18 -08:00
keys.mk ["n"] "gc${k}" "${k}<esc>Vcx<esc><cmd>normal gcc<cr>fxa<bs>"
"Add Comment ${d}"
)
2024-11-24 19:46:48 -08:00
{
o = "Below";
O = "Above";
}
)
#
2024-11-24 19:46:48 -08:00
# New File - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 19:05:18 -08:00
++ [(keys.mk ["n"] "<leader>fn" "<cmd>enew<cr>" "New File")]
#
2024-11-24 19:46:48 -08:00
# Locations/Quickfixes - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [
2024-11-25 19:05:18 -08:00
(keys.mk ["n"] "<leader>xl" "<cmd>lopen<cr>" "Location List")
(keys.mk ["n"] "<leader>xq" "<cmd>copen<cr>" "Quickfix list")
2024-11-24 19:46:48 -08:00
]
2024-11-25 17:47:14 -08:00
++ (
mapAttrsToList (
2024-11-25 17:47:14 -08:00
k: d: let
2024-11-24 19:46:48 -08:00
cmd = substring 0 4 (toLower d);
in
2024-11-25 19:05:18 -08:00
keys.mk ["n"] "${k}q" "<cmd>c${cmd}<cr>" "${d} Quickfix"
2024-11-24 19:46:48 -08:00
)
{
"[" = "Previous";
"]" = "Next";
}
)
#
2024-11-24 19:46:48 -08:00
# Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [
2024-11-25 19:05:18 -08:00
(keys.mk ["n"] "<leader>cd" (
mkRaw
# lua
"function() vim.diagnostic.open_float() end"
) "Line Diagnostics")
2024-11-24 19:46:48 -08:00
]
2024-11-25 17:47:14 -08:00
++ (
mapCartesianProduct (
2024-11-25 17:47:14 -08:00
{
dir,
key,
}: let
kmap = "${
if (dir == "Next")
then "]"
else "["
}${key}";
2024-11-24 19:46:48 -08:00
sevs = {
d = {
key = "nil";
desc = "Diagnostic";
};
e = {
key = "vim.diagnostic.severity.ERROR";
desc = "Error";
};
w = {
key = "vim.diagnostic.severity.WARN";
desc = "Warning";
};
};
cmd = toLower dir;
sev = sevs."${key}".key;
in
2024-11-25 19:05:18 -08:00
keys.mk ["n"] kmap
(
mkRaw
2024-11-25 17:47:14 -08:00
# lua
2024-11-25 19:05:18 -08:00
"function() vim.diagnostic.goto_${cmd}({ severity = ${sev} }) end"
)
"${dir} ${sevs."${key}".desc}"
2024-11-24 19:46:48 -08:00
)
{
dir = ["Next" "Prev"];
key = ["d" "e" "w"];
2024-11-24 19:46:48 -08:00
}
)
#
2024-11-24 19:46:48 -08:00
# Quit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 19:05:18 -08:00
++ [(keys.mk ["n"] "<leader>qq" "<cmd>qa<cr>" "Quit All")]
#
2024-11-24 19:46:48 -08:00
# Inspect - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 19:05:18 -08:00
++ [(keys.mk ["n"] "<leader>ui" (mkRaw "vim.show_pos") "Inspect Position")]
#
2024-11-24 19:46:48 -08:00
# Window Management - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [
2024-11-25 19:05:18 -08:00
(keys.mkWithOpts ["n"] "<leader>w" "<C-w>" "Windows" {remap = true;})
(keys.mkWithOpts ["n"] "<leader>-" "<C-w>s" "Split Window Below" {remap = true;})
(keys.mkWithOpts ["n"] "<leader>|" "<C-w>v" "Split Window Right" {remap = true;})
(keys.mkWithOpts ["n"] "<leader>wd" "<C-w>c" "Delete Window" {remap = true;})
2024-11-24 19:46:48 -08:00
]
#
2024-11-24 19:46:48 -08:00
# Tab Management - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 17:47:14 -08:00
++ (
mapAttrsToList (
k: a: let
2024-11-25 17:47:14 -08:00
desc =
if (a == "Only")
then "Close Other Tabs"
else "${a} Tab";
in
2024-11-25 19:05:18 -08:00
keys.mk ["n"] "<leader><tab>${k}" "<cmd>tab${toLower a}<cr>" desc
)
2024-11-24 19:46:48 -08:00
{
l = "Last";
o = "Only";
f = "First";
"<Tab>" = "New";
"]" = "Next";
d = "Close";
"[" = "Previous";
}
);
}