feat: Basic keymaps using new library fn

This commit is contained in:
punkfairie 2024-11-25 18:29:33 -08:00
parent 27ba9da6f3
commit 19b11cd89e
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696
3 changed files with 107 additions and 221 deletions

26
lib/keymaps/default.nix Normal file
View file

@ -0,0 +1,26 @@
_: {
keys = rec {
mkKeymap = mode: key: action: desc: {
inherit mode key action;
options = {
inherit desc;
silent = true;
};
};
mkKeymap' =
mode: key: action:
mkKeymap mode key action null;
mkKeymapWithOpts =
mode: key: action: desc: opts:
(mkKeymap mode key action desc)
// {
options = opts;
};
mkKeymapWithOpts' =
mode: key: action: opts:
mkKeymapWithOpts mode key action null opts;
};
}

View file

@ -1,4 +1,8 @@
{lib, ...}: let {
lib,
helpers,
...
}: let
inherit inherit
(lib) (lib)
map map
@ -8,6 +12,9 @@
mapCartesianProduct mapCartesianProduct
toLower toLower
; ;
inherit (lib.marleyos.keys) mkKeymap mkKeymapWithOpts;
inherit (helpers) mkRaw;
in { in {
globals = { globals = {
mapleader = " "; mapleader = " ";
@ -103,37 +110,18 @@ in {
} }
) )
++ [ ++ [
{ (mkKeymap ["n"] "<leader>bD" "<cmd>bd<cr>" "Delete Buffer and Window")
mode = ["n"];
key = "<leader>bD";
action = "<cmd>bd<cr>";
options = {
desc = "Delete Buffer and Window";
};
}
] ]
# Clear Search/Diff Update/Redraw - - - - - - - - - - - - - - - - - - - - - # Clear Search/Diff Update/Redraw - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [
{ (mkKeymap [
mode = [
"i" "i"
"n" "n"
]; ] "<esc>" "<cmd>noh<cr><esc>" "Escape and Clear hlsearch")
key = "<esc>"; (
action = "<cmd>noh<cr><esc>"; mkKeymap ["n"] "<leader>ur" "<cmd>nohlsearch<bar>diffupdate<bar>normal! <C-l><cr>"
options = { "Redraw / Clear hlsearch / Diff Update"
desc = "Escape and Clear hlsearch"; )
};
}
{
mode = ["n"];
key = "<leader>ur";
action = "<cmd>nohlsearch<bar>diffupdate<bar>normal! <C-l><cr>";
options = {
desc = "Redraw / Clear hlsearch / Diff Update";
};
}
] ]
# Better n & N - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Better n & N - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (
@ -192,16 +180,7 @@ in {
) )
# 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")]
{
mode = ["n"];
key = "<leader>K";
action = "<cmd>norm! K<cr>";
options = {
desc = "Search <keywordprog> for word";
};
}
]
# Better Indenting - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Better Indenting - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (
map map
@ -232,35 +211,11 @@ in {
} }
) )
# New File - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # New File - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [(mkKeymap ["n"] "<leader>fn" "<cmd>enew<cr>" "New File")]
{
mode = ["n"];
key = "<leader>fn";
action = "<cmd>enew<cr>";
options = {
desc = "New File";
};
}
]
# Locations/Quickfixes - - - - - - - - - - - - - - - - - - - - - - - - - - - # Locations/Quickfixes - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [
{ (mkKeymap ["n"] "<leader>xl" "<cmd>lopen<cr>" "Location List")
mode = ["n"]; (mkKeymap ["n"] "<leader>xq" "<cmd>copen<cr>" "Quickfix list")
key = "<leader>xl";
action = "<cmd>lopen<cr>";
options = {
desc = "Location List";
};
}
{
mode = ["n"];
key = "<leader>xq";
action = "<cmd>copen<cr>";
options = {
desc = "Quickfix list";
};
}
] ]
++ ( ++ (
mapAttrsToList mapAttrsToList
@ -283,16 +238,11 @@ in {
) )
# Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [
{ (mkKeymap ["n"] "<leader>cd" (
mode = ["n"]; mkRaw
key = "<leader>cd";
action.__raw =
# lua # lua
"function() vim.diagnostic.open_float() end"; "function() vim.diagnostic.open_float() end"
options = { ) "Line Diagnostics")
desc = "Line Diagnostics";
};
}
] ]
++ ( ++ (
mapCartesianProduct mapCartesianProduct
@ -346,70 +296,15 @@ in {
} }
) )
# Quit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Quit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [(mkKeymap ["n"] "<leader>qq" "<cmd>qa<cr>" "Quit All")]
{
mode = ["n"];
key = "<leader>qq";
action = "<cmd>qa<cr>";
options = {
desc = "Quit All";
};
}
]
# Inspect - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Inspect - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [(mkKeymap ["n"] "<leader>ui" (mkRaw "vim.show_pos") "Inspect Position")]
{
mode = ["n"];
key = "<leader>ui";
action.__raw =
# lua
"vim.show_pos";
options = {
desc = "Inspect Position";
};
}
]
# Window Management - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Window Management - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [
{ (mkKeymapWithOpts ["n"] "<leader>w" "<C-w>" "Windows" {remap = true;})
mode = ["n"]; (mkKeymapWithOpts ["n"] "<leader>-" "<C-w>s" "Split Window Below" {remap = true;})
key = "<leader>w"; (mkKeymapWithOpts ["n"] "<leader>|" "<C-w>v" "Split Window Right" {remap = true;})
action = "<C-w>"; (mkKeymapWithOpts ["n"] "<leader>wd" "<C-w>c" "Delete Window" {remap = true;})
options = {
desc = "Windows";
remap = true;
};
}
{
mode = ["n"];
key = "<leader>-";
action = "<C-w>s";
options = {
desc = "Split Window Below";
remap = true;
};
}
{
mode = ["n"];
key = "<leader>|";
action = "<C-w>v";
options = {
desc = "Split Window Right";
remap = true;
};
}
{
mode = ["n"];
key = "<leader>wd";
action = "<C-w>c";
options = {
desc = "Delete Window";
remap = true;
};
}
] ]
# Tab Management - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Tab Management - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ ( ++ (

View file

@ -1,4 +1,12 @@
{pkgs, ...}: { {
pkgs,
lib,
helpers,
...
}: let
inherit (helpers) mkRaw;
inherit (lib.marleyos.keys) mkKeymap;
in {
extraPackages = [pkgs.lazygit]; extraPackages = [pkgs.lazygit];
plugins.snacks = { plugins.snacks = {
@ -14,98 +22,55 @@
}; };
keymaps = [ keymaps = [
{ (mkKeymap ["n"] "<leader>un" (
mode = ["n"]; mkRaw
key = "<leader>un";
action.__raw =
# lua # lua
"function() Snacks.notifier.hide() end"; "function() Snacks.notifier.hide() end"
options = { ) "Dismiss All Notifications")
desc = "Dismiss All Notifications";
};
}
{ (mkKeymap ["n"] "<leader>bd" (
mode = ["n"]; mkRaw
key = "<leader>bd";
action.__raw =
# lua # lua
"function() Snacks.bufdelete() end"; "function() Snacks.bufdelete() end"
options = { ) "Delete Buffer")
desc = "Delete Buffer";
};
}
{ (mkKeymap ["n"] "<leader>bo" (
mode = ["n"]; mkRaw
key = "<leader>bo";
action.__raw =
# lua # lua
"function() Snacks.bufdelete.other() end"; "function() Snacks.bufdelete.other() end"
options = { ) "Delete Other Buffers")
desc = "Delete Other Buffers";
};
}
# LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{ (mkKeymap ["n"] "<leader>gg" (
mode = ["n"]; mkRaw
key = "<leader>gg";
action.__raw =
# lua # lua
"function() Snacks.lazygit() end"; "function() Snacks.lazygit() end"
options = { ) "Lazygit")
desc = "Lazygit";
};
}
{ (mkKeymap ["n"] "<leader>gf" (
mode = ["n"]; mkRaw
key = "<leader>gf";
action.__raw =
# lua # lua
"function() Snacks.lazygit.log_file() end"; "function() Snacks.lazygit.log_file() end"
options = { ) "Lazygit Current File History")
desc = "Lazygit Current File History";
};
}
{ (mkKeymap ["n"] "<leader>gl" (
mode = ["n"]; mkRaw
key = "<leader>gl";
action.__raw =
# lua # lua
"function() Snacks.lazygit.log() end"; "function() Snacks.lazygit.log() end"
options = { ) "Lazygit Log")
desc = "Lazygit Log";
};
}
# Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{ (mkKeymap ["n"] "<leader>gb" (
mode = ["n"]; mkRaw
key = "<leader>gb";
action.__raw =
# lua # lua
"function() Snacks.git.blame_line() end"; "function() Snacks.git.blame_line() end"
options = { ) "Git Blame Line")
desc = "Gib Blame Line";
};
}
{ (mkKeymap ["n" "x"] "<leader>gB" (
mode = [ mkRaw
"n"
"x"
];
key = "<leader>gB";
action.__raw =
# lua # lua
"function() Snacks.gitbrowse() end"; "function() Snacks.gitbrowse() end"
options = { ) "Git Browse")
desc = "Git Browse";
};
}
]; ];
# Toggles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Toggles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -