From 19b11cd89e2fb7b6a35284c8dd6ba1b8d0b9c6cb Mon Sep 17 00:00:00 2001 From: punkfairie Date: Mon, 25 Nov 2024 18:29:33 -0800 Subject: [PATCH] feat: Basic keymaps using new library fn --- lib/keymaps/default.nix | 26 +++ modules/nixvim/keymaps/default.nix | 169 ++++-------------- .../nixvim/plugins/base/snacks/default.nix | 133 +++++--------- 3 files changed, 107 insertions(+), 221 deletions(-) create mode 100644 lib/keymaps/default.nix diff --git a/lib/keymaps/default.nix b/lib/keymaps/default.nix new file mode 100644 index 0000000..e330c29 --- /dev/null +++ b/lib/keymaps/default.nix @@ -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; + }; +} diff --git a/modules/nixvim/keymaps/default.nix b/modules/nixvim/keymaps/default.nix index b8c255f..05cba6a 100644 --- a/modules/nixvim/keymaps/default.nix +++ b/modules/nixvim/keymaps/default.nix @@ -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 = "bD"; - action = "bd"; - options = { - desc = "Delete Buffer and Window"; - }; - } + (mkKeymap ["n"] "bD" "bd" "Delete Buffer and Window") ] # Clear Search/Diff Update/Redraw - - - - - - - - - - - - - - - - - - - - - ++ [ - { - mode = [ - "i" - "n" - ]; - key = ""; - action = "noh"; - options = { - desc = "Escape and Clear hlsearch"; - }; - } - - { - mode = ["n"]; - key = "ur"; - action = "nohlsearchdiffupdatenormal! "; - options = { - desc = "Redraw / Clear hlsearch / Diff Update"; - }; - } + (mkKeymap [ + "i" + "n" + ] "" "noh" "Escape and Clear hlsearch") + ( + mkKeymap ["n"] "ur" "nohlsearchdiffupdatenormal! " + "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 = "K"; - action = "norm! K"; - options = { - desc = "Search for word"; - }; - } - ] + ++ [(mkKeymap ["n"] "K" "norm! K" "Search for word")] # Better Indenting - - - - - - - - - - - - - - - - - - - - - - - - - - - - ++ ( map @@ -232,35 +211,11 @@ in { } ) # New File - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ++ [ - { - mode = ["n"]; - key = "fn"; - action = "enew"; - options = { - desc = "New File"; - }; - } - ] + ++ [(mkKeymap ["n"] "fn" "enew" "New File")] # Locations/Quickfixes - - - - - - - - - - - - - - - - - - - - - - - - - - - ++ [ - { - mode = ["n"]; - key = "xl"; - action = "lopen"; - options = { - desc = "Location List"; - }; - } - - { - mode = ["n"]; - key = "xq"; - action = "copen"; - options = { - desc = "Quickfix list"; - }; - } + (mkKeymap ["n"] "xl" "lopen" "Location List") + (mkKeymap ["n"] "xq" "copen" "Quickfix list") ] ++ ( mapAttrsToList @@ -283,16 +238,11 @@ in { ) # Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ++ [ - { - mode = ["n"]; - key = "cd"; - action.__raw = - # lua - "function() vim.diagnostic.open_float() end"; - options = { - desc = "Line Diagnostics"; - }; - } + (mkKeymap ["n"] "cd" ( + mkRaw + # lua + "function() vim.diagnostic.open_float() end" + ) "Line Diagnostics") ] ++ ( mapCartesianProduct @@ -346,70 +296,15 @@ in { } ) # Quit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ++ [ - { - mode = ["n"]; - key = "qq"; - action = "qa"; - options = { - desc = "Quit All"; - }; - } - ] + ++ [(mkKeymap ["n"] "qq" "qa" "Quit All")] # Inspect - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ++ [ - { - mode = ["n"]; - key = "ui"; - action.__raw = - # lua - "vim.show_pos"; - options = { - desc = "Inspect Position"; - }; - } - ] + ++ [(mkKeymap ["n"] "ui" (mkRaw "vim.show_pos") "Inspect Position")] # Window Management - - - - - - - - - - - - - - - - - - - - - - - - - - - - ++ [ - { - mode = ["n"]; - key = "w"; - action = ""; - options = { - desc = "Windows"; - remap = true; - }; - } - - { - mode = ["n"]; - key = "-"; - action = "s"; - options = { - desc = "Split Window Below"; - remap = true; - }; - } - - { - mode = ["n"]; - key = "|"; - action = "v"; - options = { - desc = "Split Window Right"; - remap = true; - }; - } - - { - mode = ["n"]; - key = "wd"; - action = "c"; - options = { - desc = "Delete Window"; - remap = true; - }; - } + (mkKeymapWithOpts ["n"] "w" "" "Windows" {remap = true;}) + (mkKeymapWithOpts ["n"] "-" "s" "Split Window Below" {remap = true;}) + (mkKeymapWithOpts ["n"] "|" "v" "Split Window Right" {remap = true;}) + (mkKeymapWithOpts ["n"] "wd" "c" "Delete Window" {remap = true;}) ] # Tab Management - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ++ ( diff --git a/modules/nixvim/plugins/base/snacks/default.nix b/modules/nixvim/plugins/base/snacks/default.nix index dbf3dcb..daf0470 100644 --- a/modules/nixvim/plugins/base/snacks/default.nix +++ b/modules/nixvim/plugins/base/snacks/default.nix @@ -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 = "un"; - action.__raw = - # lua - "function() Snacks.notifier.hide() end"; - options = { - desc = "Dismiss All Notifications"; - }; - } + (mkKeymap ["n"] "un" ( + mkRaw + # lua + "function() Snacks.notifier.hide() end" + ) "Dismiss All Notifications") - { - mode = ["n"]; - key = "bd"; - action.__raw = - # lua - "function() Snacks.bufdelete() end"; - options = { - desc = "Delete Buffer"; - }; - } + (mkKeymap ["n"] "bd" ( + mkRaw + # lua + "function() Snacks.bufdelete() end" + ) "Delete Buffer") - { - mode = ["n"]; - key = "bo"; - action.__raw = - # lua - "function() Snacks.bufdelete.other() end"; - options = { - desc = "Delete Other Buffers"; - }; - } + (mkKeymap ["n"] "bo" ( + mkRaw + # lua + "function() Snacks.bufdelete.other() end" + ) "Delete Other Buffers") # LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { - mode = ["n"]; - key = "gg"; - action.__raw = - # lua - "function() Snacks.lazygit() end"; - options = { - desc = "Lazygit"; - }; - } + (mkKeymap ["n"] "gg" ( + mkRaw + # lua + "function() Snacks.lazygit() end" + ) "Lazygit") - { - mode = ["n"]; - key = "gf"; - action.__raw = - # lua - "function() Snacks.lazygit.log_file() end"; - options = { - desc = "Lazygit Current File History"; - }; - } + (mkKeymap ["n"] "gf" ( + mkRaw + # lua + "function() Snacks.lazygit.log_file() end" + ) "Lazygit Current File History") - { - mode = ["n"]; - key = "gl"; - action.__raw = - # lua - "function() Snacks.lazygit.log() end"; - options = { - desc = "Lazygit Log"; - }; - } + (mkKeymap ["n"] "gl" ( + mkRaw + # lua + "function() Snacks.lazygit.log() end" + ) "Lazygit Log") # Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { - mode = ["n"]; - key = "gb"; - action.__raw = - # lua - "function() Snacks.git.blame_line() end"; - options = { - desc = "Gib Blame Line"; - }; - } + (mkKeymap ["n"] "gb" ( + mkRaw + # lua + "function() Snacks.git.blame_line() end" + ) "Git Blame Line") - { - mode = [ - "n" - "x" - ]; - key = "gB"; - action.__raw = - # lua - "function() Snacks.gitbrowse() end"; - options = { - desc = "Git Browse"; - }; - } + (mkKeymap ["n" "x"] "gB" ( + mkRaw + # lua + "function() Snacks.gitbrowse() end" + ) "Git Browse") ]; # Toggles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -