From 562e1847b0083c28cc67434d6f2d43b937c1fa2b Mon Sep 17 00:00:00 2001 From: n3oney Date: Wed, 12 Apr 2023 21:13:00 +0200 Subject: [PATCH] feat: add nvim-bufferline keybindings --- modules/tabline/nvim-bufferline/config.nix | 35 +++++++++---------- .../nvim-bufferline/nvim-bufferline.nix | 18 +++++++--- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/modules/tabline/nvim-bufferline/config.nix b/modules/tabline/nvim-bufferline/config.nix index e770eeb..9e73cbe 100644 --- a/modules/tabline/nvim-bufferline/config.nix +++ b/modules/tabline/nvim-bufferline/config.nix @@ -6,6 +6,10 @@ with lib; with builtins; let cfg = config.vim.tabline.nvimBufferline; + self = import ./nvim-bufferline.nix { + inherit lib; + }; + mappings = self.options.vim.tabline.nvimBufferline.mappings; in { config = mkIf cfg.enable ( let @@ -23,25 +27,18 @@ in { "bufdelete-nvim" ]; - vim.maps.normal = { - "bn" = {action = ":BufferLineCycleNext";}; - "bp" = {action = ":BufferLineCyclePrev";}; - "bc" = {action = ":BufferLinePick";}; - "bse" = {action = ":BufferLineSortByExtension";}; - "bsd" = {action = ":BufferLineSortByDirectory";}; - "bsi" = {action = ":lua require'bufferline'.sort_buffers_by(function (buf_a, buf_b) return buf_a.id < buf_b.id end)";}; - "bmn" = {action = ":BufferLineMoveNext";}; - "bmp" = {action = ":BufferLineMovePrev";}; - "b1" = {action = "BufferLineGoToBuffer 1";}; - "b2" = {action = "BufferLineGoToBuffer 2";}; - "b3" = {action = "BufferLineGoToBuffer 3";}; - "b4" = {action = "BufferLineGoToBuffer 4";}; - "b5" = {action = "BufferLineGoToBuffer 5";}; - "b6" = {action = "BufferLineGoToBuffer 6";}; - "b7" = {action = "BufferLineGoToBuffer 7";}; - "b8" = {action = "BufferLineGoToBuffer 8";}; - "b9" = {action = "BufferLineGoToBuffer 9";}; - }; + vim.maps.normal = mkMerge [ + (mkLuaBinding cfg.mappings.closeCurrent "require(\"bufdelete\").bufdelete" mappings.closeCurrent.description) + (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext" mappings.cycleNext.description) + (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext" mappings.cycleNext.description) + (mkBinding cfg.mappings.cyclePrevious ":BufferLineCyclePrev" mappings.cyclePrevious.description) + (mkBinding cfg.mappings.pick ":BufferLinePick" mappings.pick.description) + (mkBinding cfg.mappings.sortByExtension ":BufferLineSortByExtension" mappings.sortByExtension.description) + (mkBinding cfg.mappings.sortByDirectory ":BufferLineSortByDirectory" mappings.sortByDirectory.description) + (mkLuaBinding cfg.mappings.sortById "function() require(\"bufferline\").sort_buffers_by(function (buf_a, buf_b) return buf_a.id < buf_b.id end) end" mappings.sortById.description) + (mkBinding cfg.mappings.moveNext ":BufferLineMoveNext" mappings.moveNext.description) + (mkBinding cfg.mappings.movePrevious ":BufferLineMovePrev" mappings.movePrevious.description) + ]; vim.luaConfigRC.nvimBufferline = nvim.dag.entryAnywhere '' require("bufferline").setup{ diff --git a/modules/tabline/nvim-bufferline/nvim-bufferline.nix b/modules/tabline/nvim-bufferline/nvim-bufferline.nix index ad707bf..32e2dd3 100644 --- a/modules/tabline/nvim-bufferline/nvim-bufferline.nix +++ b/modules/tabline/nvim-bufferline/nvim-bufferline.nix @@ -1,11 +1,19 @@ -{ - config, - lib, - ... -}: +{lib, ...}: with lib; with builtins; { options.vim.tabline.nvimBufferline = { + mappings = { + closeCurrent = mkMappingOption "Close buffer" null; + cycleNext = mkMappingOption "Next buffer" "bn"; + cyclePrevious = mkMappingOption "Previous buffer" "bp"; + pick = mkMappingOption "Pick buffer" "bc"; + sortByExtension = mkMappingOption "Sort buffers by extension" "bse"; + sortByDirectory = mkMappingOption "Sort buffers by directory" "bsd"; + sortById = mkMappingOption "Sort buffers by ID" "bsi"; + moveNext = mkMappingOption "Move next buffer" "bmn"; + movePrevious = mkMappingOption "Move previous buffer" "bmp"; + }; + enable = mkEnableOption "Enable nvim-bufferline-lua as a bufferline"; }; }