From e21096203ac98ebd9b851248e704db356b9f98c1 Mon Sep 17 00:00:00 2001 From: n3oney Date: Wed, 12 Apr 2023 23:58:09 +0200 Subject: [PATCH] feat: add comment.nvim keybindings --- .../comments/comment-nvim/comment-nvim.nix | 17 +++++++--- modules/comments/comment-nvim/config.nix | 33 ++++++++++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/modules/comments/comment-nvim/comment-nvim.nix b/modules/comments/comment-nvim/comment-nvim.nix index 0e1369b..6ffbce0 100644 --- a/modules/comments/comment-nvim/comment-nvim.nix +++ b/modules/comments/comment-nvim/comment-nvim.nix @@ -1,11 +1,18 @@ -{ - config, - lib, - ... -}: +{lib, ...}: with lib; with builtins; { options.vim.comments.comment-nvim = { enable = mkEnableOption "Enable comment-nvim"; + + mappings = { + toggleCurrentLine = mkMappingOption "Toggle current line comment" "gcc"; + toggleCurrentBlock = mkMappingOption "Toggle current block comment" "gbc"; + + toggleOpLeaderLine = mkMappingOption "Toggle line comment" "gc"; + toggleOpLeaderBlock = mkMappingOption "Toggle block comment" "gb"; + + toggleSelectedLine = mkMappingOption "Toggle selected comment" "gc"; + toggleSelectedBlock = mkMappingOption "Toggle selected block" "gb"; + }; }; } diff --git a/modules/comments/comment-nvim/config.nix b/modules/comments/comment-nvim/config.nix index 1a2e150..bc29111 100644 --- a/modules/comments/comment-nvim/config.nix +++ b/modules/comments/comment-nvim/config.nix @@ -6,14 +6,45 @@ with lib; with builtins; let cfg = config.vim.comments.comment-nvim; + self = import ./comment-nvim.nix { + inherit lib; + }; + mappings = self.options.vim.comments.comment-nvim.mappings; in { config = mkIf cfg.enable { vim.startPlugins = [ "comment-nvim" ]; + vim.maps.normal = mkMerge [ + (mkBinding cfg.mappings.toggleOpLeaderLine "(comment_toggle_linewise)" mappings.toggleOpLeaderLine.description) + (mkBinding cfg.mappings.toggleOpLeaderBlock "(comment_toggle_blockwise)" mappings.toggleOpLeaderBlock.description) + + (mkExprBinding cfg.mappings.toggleCurrentLine '' + function() + return vim.api.nvim_get_vvar('count') == 0 and '(comment_toggle_linewise_current)' + or '(comment_toggle_linewise_count)' + end + '' + mappings.toggleCurrentLine.description) + (mkExprBinding cfg.mappings.toggleCurrentBlock '' + function() + return vim.api.nvim_get_vvar('count') == 0 and '(comment_toggle_blockwise_current)' + or '(comment_toggle_blockwise_count)' + end + '' + mappings.toggleCurrentBlock.description) + ]; + + vim.maps.visualOnly = mkMerge [ + (mkBinding cfg.mappings.toggleSelectedLine "(comment_toggle_linewise_visual)" mappings.toggleSelectedLine.description) + (mkBinding cfg.mappings.toggleSelectedBlock "(comment_toggle_blockwise_visual)" mappings.toggleSelectedBlock.description) + ]; + vim.luaConfigRC.comment-nvim = nvim.dag.entryAnywhere '' - require('Comment').setup() + require('Comment').setup({ + mappings = { basic = false, extra = false, }, + }) ''; }; }