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
(lib)
map
@ -8,6 +12,9 @@
mapCartesianProduct
toLower
;
inherit (lib.marleyos.keys) mkKeymap mkKeymapWithOpts;
inherit (helpers) mkRaw;
in {
globals = {
mapleader = " ";
@ -103,37 +110,18 @@ in {
}
)
++ [
{
mode = ["n"];
key = "<leader>bD";
action = "<cmd>bd<cr>";
options = {
desc = "Delete Buffer and Window";
};
}
(mkKeymap ["n"] "<leader>bD" "<cmd>bd<cr>" "Delete Buffer and Window")
]
# Clear Search/Diff Update/Redraw - - - - - - - - - - - - - - - - - - - - -
++ [
{
mode = [
"i"
"n"
];
key = "<esc>";
action = "<cmd>noh<cr><esc>";
options = {
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";
};
}
(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>"
"Redraw / Clear hlsearch / Diff Update"
)
]
# Better n & N - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ (
@ -192,16 +180,7 @@ in {
)
# Search Docs (keywordprog) - - - - - - - - - - - - - - - - - - - - - - - -
# https://til.codeinthehole.com/posts/about-how-to-use-keywordprg-effectively/
++ [
{
mode = ["n"];
key = "<leader>K";
action = "<cmd>norm! K<cr>";
options = {
desc = "Search <keywordprog> for word";
};
}
]
++ [(mkKeymap ["n"] "<leader>K" "<cmd>norm! K<cr>" "Search <keywordprog> for word")]
# Better Indenting - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ (
map
@ -232,35 +211,11 @@ in {
}
)
# New File - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [
{
mode = ["n"];
key = "<leader>fn";
action = "<cmd>enew<cr>";
options = {
desc = "New File";
};
}
]
++ [(mkKeymap ["n"] "<leader>fn" "<cmd>enew<cr>" "New File")]
# Locations/Quickfixes - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [
{
mode = ["n"];
key = "<leader>xl";
action = "<cmd>lopen<cr>";
options = {
desc = "Location List";
};
}
{
mode = ["n"];
key = "<leader>xq";
action = "<cmd>copen<cr>";
options = {
desc = "Quickfix list";
};
}
(mkKeymap ["n"] "<leader>xl" "<cmd>lopen<cr>" "Location List")
(mkKeymap ["n"] "<leader>xq" "<cmd>copen<cr>" "Quickfix list")
]
++ (
mapAttrsToList
@ -283,16 +238,11 @@ in {
)
# Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [
{
mode = ["n"];
key = "<leader>cd";
action.__raw =
# lua
"function() vim.diagnostic.open_float() end";
options = {
desc = "Line Diagnostics";
};
}
(mkKeymap ["n"] "<leader>cd" (
mkRaw
# lua
"function() vim.diagnostic.open_float() end"
) "Line Diagnostics")
]
++ (
mapCartesianProduct
@ -346,70 +296,15 @@ in {
}
)
# Quit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [
{
mode = ["n"];
key = "<leader>qq";
action = "<cmd>qa<cr>";
options = {
desc = "Quit All";
};
}
]
++ [(mkKeymap ["n"] "<leader>qq" "<cmd>qa<cr>" "Quit All")]
# Inspect - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [
{
mode = ["n"];
key = "<leader>ui";
action.__raw =
# lua
"vim.show_pos";
options = {
desc = "Inspect Position";
};
}
]
++ [(mkKeymap ["n"] "<leader>ui" (mkRaw "vim.show_pos") "Inspect Position")]
# Window Management - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [
{
mode = ["n"];
key = "<leader>w";
action = "<C-w>";
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;
};
}
(mkKeymapWithOpts ["n"] "<leader>w" "<C-w>" "Windows" {remap = true;})
(mkKeymapWithOpts ["n"] "<leader>-" "<C-w>s" "Split Window Below" {remap = true;})
(mkKeymapWithOpts ["n"] "<leader>|" "<C-w>v" "Split Window Right" {remap = true;})
(mkKeymapWithOpts ["n"] "<leader>wd" "<C-w>c" "Delete Window" {remap = true;})
]
# 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];
plugins.snacks = {
@ -14,98 +22,55 @@
};
keymaps = [
{
mode = ["n"];
key = "<leader>un";
action.__raw =
# lua
"function() Snacks.notifier.hide() end";
options = {
desc = "Dismiss All Notifications";
};
}
(mkKeymap ["n"] "<leader>un" (
mkRaw
# lua
"function() Snacks.notifier.hide() end"
) "Dismiss All Notifications")
{
mode = ["n"];
key = "<leader>bd";
action.__raw =
# lua
"function() Snacks.bufdelete() end";
options = {
desc = "Delete Buffer";
};
}
(mkKeymap ["n"] "<leader>bd" (
mkRaw
# lua
"function() Snacks.bufdelete() end"
) "Delete Buffer")
{
mode = ["n"];
key = "<leader>bo";
action.__raw =
# lua
"function() Snacks.bufdelete.other() end";
options = {
desc = "Delete Other Buffers";
};
}
(mkKeymap ["n"] "<leader>bo" (
mkRaw
# lua
"function() Snacks.bufdelete.other() end"
) "Delete Other Buffers")
# LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{
mode = ["n"];
key = "<leader>gg";
action.__raw =
# lua
"function() Snacks.lazygit() end";
options = {
desc = "Lazygit";
};
}
(mkKeymap ["n"] "<leader>gg" (
mkRaw
# lua
"function() Snacks.lazygit() end"
) "Lazygit")
{
mode = ["n"];
key = "<leader>gf";
action.__raw =
# lua
"function() Snacks.lazygit.log_file() end";
options = {
desc = "Lazygit Current File History";
};
}
(mkKeymap ["n"] "<leader>gf" (
mkRaw
# lua
"function() Snacks.lazygit.log_file() end"
) "Lazygit Current File History")
{
mode = ["n"];
key = "<leader>gl";
action.__raw =
# lua
"function() Snacks.lazygit.log() end";
options = {
desc = "Lazygit Log";
};
}
(mkKeymap ["n"] "<leader>gl" (
mkRaw
# lua
"function() Snacks.lazygit.log() end"
) "Lazygit Log")
# Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{
mode = ["n"];
key = "<leader>gb";
action.__raw =
# lua
"function() Snacks.git.blame_line() end";
options = {
desc = "Gib Blame Line";
};
}
(mkKeymap ["n"] "<leader>gb" (
mkRaw
# lua
"function() Snacks.git.blame_line() end"
) "Git Blame Line")
{
mode = [
"n"
"x"
];
key = "<leader>gB";
action.__raw =
# lua
"function() Snacks.gitbrowse() end";
options = {
desc = "Git Browse";
};
}
(mkKeymap ["n" "x"] "<leader>gB" (
mkRaw
# lua
"function() Snacks.gitbrowse() end"
) "Git Browse")
];
# Toggles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -