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