From 439437402d299991a7087c20c4a3287201cd0309 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 21 Apr 2024 11:46:13 +0300 Subject: [PATCH] modules: add hop-nvim --- flake.nix | 4 ++ modules/gitsigns-nvim.nix | 15 +++++-- modules/hop-nvim.nix | 92 +++++++++++++++++++++++++++++++++++++++ modules/nvim-tree-lua.nix | 13 ++++-- 4 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 modules/hop-nvim.nix diff --git a/flake.nix b/flake.nix index 80dd7bf..f40e4fe 100644 --- a/flake.nix +++ b/flake.nix @@ -254,6 +254,7 @@ nvim-treesitter = { }; gitsigns-nvim = { }; neoformat = { }; + hop-nvim = { }; }; plugins = with prev.nix2lua.lib; { @@ -272,6 +273,9 @@ lualine_z = [ "location" "mode" ]; }; }); + nvim-colorizer = pipe1 + (require "colorizer") + (call0 "setup"); }; }); diff --git a/modules/gitsigns-nvim.nix b/modules/gitsigns-nvim.nix index e5e1876..2c27106 100644 --- a/modules/gitsigns-nvim.nix +++ b/modules/gitsigns-nvim.nix @@ -2,8 +2,8 @@ with nix2lua.lib; -{ configs ? { } -, keymaps ? [ +let + defaultKeymaps = [ { mode = "n"; bind = "]h"; command = raw "next_hunk"; } { mode = "n"; bind = "[h"; command = raw "prev_hunk"; } { mode = "n"; bind = "gs"; command = raw "gs.stage_hunk"; } @@ -15,11 +15,18 @@ with nix2lua.lib; { mode = "n"; bind = "gD"; command = lambda0 (call "gs.diffthis" "~"); } { mode = "n"; bind = "gtb"; command = raw "gs.toggle_current_line_blame"; } { mode = "n"; bind = "gtd"; command = raw "gs.toggle_deleted"; } - ] + ]; +in + +{ configs ? { } +, keymaps ? defaultKeymaps +, extraKeymaps ? [ ] }: let - bufferedKeymaps = map (args: lib.recursiveUpdate args { opts.buffer = var "bufnr"; }) keymaps; + bufferedKeymaps = map + (args: lib.recursiveUpdate args { opts.buffer = var "bufnr"; }) + (keymaps ++ extraKeymaps); in { gitsigns-nvim = [ diff --git a/modules/hop-nvim.nix b/modules/hop-nvim.nix new file mode 100644 index 0000000..5a657d4 --- /dev/null +++ b/modules/hop-nvim.nix @@ -0,0 +1,92 @@ +{ nix2lua, vim, ... }: + +with nix2lua.lib; + +let + hintDirAfter = var "hint.HintDirection.AFTER_CURSOR"; + hintDirBefore = var "hint.HintDirection.BEFORE_CURSOR"; + + defaultKeymaps = [ + { mode = ""; bind = "hc"; command = "HopChar1"; } + { + mode = ""; + bind = "hf"; + command = lambda0 (call "hop.hint_char1" { + direction = hintDirAfter; + current_line_only = true; + }); + } + { + mode = ""; + bind = "hF"; + command = lambda0 (call "hop.hint_char1" { + direction = hintDirBefore; + current_line_only = true; + }); + } + { + mode = ""; + bind = "hbc"; + command = lambda0 (call "hop.hint_char1" { direction = hintDirAfter; }); + } + { + mode = ""; + bind = "htc"; + command = lambda0 (call "hop.hint_char1" { direction = hintDirBefore; }); + } + { + mode = ""; + bind = "hw"; + command = "HopWord"; + } + { + mode = ""; + bind = "hbw"; + command = lambda0 (call "hop.hint_words" { direction = hintDirAfter; }); + } + { + mode = ""; + bind = "htw"; + command = lambda0 (call "hop.hint_words" { direction = hintDirBefore; }); + } + { + mode = ""; + bind = "hp"; + command = "HopPattern"; + } + { + mode = ""; + bind = "hbp"; + command = lambda0 (call "hop.hint_patterns" { direction = hintDirAfter; }); + } + { + mode = ""; + bind = "htp"; + command = lambda0 (call "hop.hint_patterns" { direction = hintDirBefore; }); + } + { + mode = ""; + bind = "hbv"; + command = lambda0 (call "hop.hint_vertical" { direction = hintDirAfter; }); + } + { + mode = ""; + bind = "htv"; + command = lambda0 (call "hop.hint_vertical" { direction = hintDirBefore; }); + } + ]; +in + +{ configs ? { } +, keymaps ? defaultKeymaps +, extraKeymaps ? [ ] +}: + +{ + hop-nvim = [ + (local (set "hop" (require "hop"))) + (pipe1 (var "hop") (call "setup" configs)) + + (local (set "hint" (require "hop.hint"))) + ] ++ map vim.keymap.set (keymaps ++ extraKeymaps); +} diff --git a/modules/nvim-tree-lua.nix b/modules/nvim-tree-lua.nix index 108ea90..9ea511f 100644 --- a/modules/nvim-tree-lua.nix +++ b/modules/nvim-tree-lua.nix @@ -1,10 +1,15 @@ { nix2lua, vim, ... }: -{ configs ? { } -, keymaps ? [ +let + defaultKeymaps = [ { mode = "n"; bind = "nt"; command = "NvimTreeToggle"; } { mode = "n"; bind = "nf"; command = "NvimTreeFindFile"; } - ] + ]; +in + +{ configs ? { } +, keymaps ? defaultKeymaps +, extraKeymaps ? [ ] }: with nix2lua.lib; @@ -45,6 +50,6 @@ let isEmptyVar = name: eq "" (var name); in (vim.api.nvim_create_autocmd [ "VimEnter" ] { callback = var "open_nvim_tree"; }) ] - ++ (map vim.keymap.set keymaps) + ++ map vim.keymap.set (keymaps ++ extraKeymaps) ); }