From 9365a7753e5b32de6af5b34a3dcb6f8fcccd5dc1 Mon Sep 17 00:00:00 2001 From: n3oney Date: Wed, 5 Apr 2023 00:06:30 +0200 Subject: [PATCH 1/8] feat: toggleterm keybindings --- modules/terminal/toggleterm/config.nix | 2 +- modules/terminal/toggleterm/toggleterm.nix | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/terminal/toggleterm/config.nix b/modules/terminal/toggleterm/config.nix index 9e98bb1..c4934dc 100644 --- a/modules/terminal/toggleterm/config.nix +++ b/modules/terminal/toggleterm/config.nix @@ -14,7 +14,7 @@ in { vim.luaConfigRC.toggleterm = nvim.dag.entryAnywhere '' require("toggleterm").setup({ - open_mapping = [[]], + open_mapping = '${cfg.mappings.open}', direction = '${toString cfg.direction}', -- TODO: this should probably be turned into a module that uses the lua function if and only if the user has not set it size = function(term) diff --git a/modules/terminal/toggleterm/toggleterm.nix b/modules/terminal/toggleterm/toggleterm.nix index e2ed940..8c60ea8 100644 --- a/modules/terminal/toggleterm/toggleterm.nix +++ b/modules/terminal/toggleterm/toggleterm.nix @@ -7,6 +7,13 @@ with lib; with builtins; { options.vim.terminal.toggleterm = { enable = mkEnableOption "Enable toggleterm as a replacement to built-in terminal command"; + mappings = { + open = mkOption { + type = types.str; + description = "The keymapping to open toggleterm"; + default = ""; + }; + }; direction = mkOption { type = types.enum ["horizontal" "vertical" "tab" "float"]; default = "horizontal"; From 5915262864480e71e6b2c6855c4d45a4d4cda962 Mon Sep 17 00:00:00 2001 From: n3oney Date: Wed, 5 Apr 2023 00:53:21 +0200 Subject: [PATCH 2/8] feat: add Copilot keybindings --- modules/assistant/copilot/config.nix | 23 ++++++++++ modules/assistant/copilot/copilot.nix | 62 +++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/modules/assistant/copilot/config.nix b/modules/assistant/copilot/config.nix index 62d0251..4ecac27 100644 --- a/modules/assistant/copilot/config.nix +++ b/modules/assistant/copilot/config.nix @@ -7,6 +7,10 @@ with lib; with builtins; let cfg = config.vim.assistant.copilot; + keyOrFalse = key: + if key != null + then "'${key}'" + else "false"; in { config = mkIf cfg.enable { vim.startPlugins = [ @@ -18,6 +22,25 @@ in { require("copilot").setup({ -- available options: https://github.com/zbirenbaum/copilot.lua copilot_node_command = "${cfg.copilot_node_command}", + panel = { + keymap = { + jump_prev = ${keyOrFalse cfg.mappings.panel.jumpPrev}, + jump_next = ${keyOrFalse cfg.mappings.panel.jumpNext}, + accept = ${keyOrFalse cfg.mappings.panel.accept}, + refresh = ${keyOrFalse cfg.mappings.panel.refresh}, + open = ${keyOrFalse cfg.mappings.panel.open}, + }, + }, + suggestion = { + keymap = { + accept = ${keyOrFalse cfg.mappings.suggestion.accept}, + accept_word = ${keyOrFalse cfg.mappings.suggestion.acceptWord}, + accept_line = ${keyOrFalse cfg.mappings.suggestion.acceptLine}, + next = ${keyOrFalse cfg.mappings.suggestion.next}, + prev = ${keyOrFalse cfg.mappings.suggestion.prev}, + dismiss = ${keyOrFalse cfg.mappings.suggestion.dismiss}, + }, + }, }) ''; }; diff --git a/modules/assistant/copilot/copilot.nix b/modules/assistant/copilot/copilot.nix index ad3e622..fcf5a5d 100644 --- a/modules/assistant/copilot/copilot.nix +++ b/modules/assistant/copilot/copilot.nix @@ -9,6 +9,68 @@ with builtins; { options.vim.assistant.copilot = { enable = mkEnableOption "Enable GitHub Copilot"; + mappings = { + panel = { + jumpPrev = mkOption { + type = types.nullOr types.str; + default = "[["; + description = "Jump to previous suggestion"; + }; + jumpNext = mkOption { + type = types.nullOr types.str; + default = "]]"; + description = "Jump to next suggestion"; + }; + accept = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Accept suggestion"; + }; + refresh = mkOption { + type = types.nullOr types.str; + default = "gr"; + description = "Refresh suggestions"; + }; + open = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Open suggestions"; + }; + }; + suggestion = { + accept = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Accept suggetion"; + }; + acceptWord = mkOption { + type = types.nullOr types.str; + default = null; + description = "Accept next word"; + }; + acceptLine = mkOption { + type = types.nullOr types.str; + default = null; + description = "Accept next line"; + }; + prev = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Previous suggestion"; + }; + next = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Next suggestion"; + }; + dismiss = mkOption { + type = types.nullOr types.str; + default = ""; + description = "Dismiss suggestion"; + }; + }; + }; + copilot_node_command = mkOption { type = types.str; default = "${lib.getExe pkgs.nodejs-slim-16_x}"; From efaf8e81b79b7c78afbb995b3d1d77af87290a11 Mon Sep 17 00:00:00 2001 From: n3oney Date: Mon, 10 Apr 2023 13:42:31 +0200 Subject: [PATCH 3/8] refactor!: use a new keymaps configuration format --- modules/basic/config.nix | 56 +++- modules/core/default.nix | 297 +++++++++++++------ modules/lsp/lspsaga/config.nix | 30 +- modules/lsp/lspsaga/lspsaga.nix | 30 +- modules/lsp/nvim-code-action-menu/config.nix | 4 +- modules/lsp/trouble/config.nix | 14 +- modules/notes/mind-nvim/config.nix | 8 +- modules/notes/todo-comments/config.nix | 8 +- modules/tabline/nvim-bufferline/config.nix | 36 +-- modules/utility/hop/config.nix | 4 +- modules/utility/telescope/config.nix | 38 +-- 11 files changed, 343 insertions(+), 182 deletions(-) diff --git a/modules/basic/config.nix b/modules/basic/config.nix index a06cae2..3fdb45e 100644 --- a/modules/basic/config.nix +++ b/modules/basic/config.nix @@ -10,21 +10,51 @@ in { config = { vim.startPlugins = ["plenary-nvim"]; - vim.nmap = mkIf cfg.disableArrows { - "" = ""; - "" = ""; - "" = ""; - "" = ""; - }; + vim.maps.normal = + mkIf cfg.disableArrows { + "" = { + action = ""; - vim.imap = mkIf cfg.disableArrows { - "" = ""; - "" = ""; - "" = ""; - "" = ""; - }; + noremap = false; + }; + "" = { + action = ""; - vim.nnoremap = mkIf cfg.mapLeaderSpace {"" = "";}; + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; + } + // mkIf cfg.mapLeaderSpace { + "" = { + action = ""; + }; + }; + + vim.maps.insert = mkIf cfg.disableArrows { + "" = { + action = ""; + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; + "" = { + action = ""; + noremap = false; + }; + }; vim.configRC.basic = nvim.dag.entryAfter ["globalsScript"] '' " Debug mode settings diff --git a/modules/core/default.nix b/modules/core/default.nix index 78232b3..6e92cff 100644 --- a/modules/core/default.nix +++ b/modules/core/default.nix @@ -19,6 +19,107 @@ with builtins; let type = with types; attrsOf (nullOr str); } // it); + + mkBool = value: description: + mkOption { + type = types.bool; + default = value; + description = description; + }; + + # Most of the keybindings code is highly inspired by pta2002/nixvim. Thank you! + mapConfigOptions = { + silent = + mkBool false + "Whether this mapping should be silent. Equivalent to adding to a map."; + + nowait = + mkBool false + "Whether to wait for extra input on ambiguous mappings. Equivalent to adding to a map."; + + script = + mkBool false + "Equivalent to adding