feat: add nvim-bufferline keybindings

This commit is contained in:
n3oney 2023-04-12 21:13:00 +02:00
parent f1bc76f495
commit 54aad74d8d
No known key found for this signature in database
GPG key ID: C786693DE727850E
2 changed files with 29 additions and 24 deletions

View file

@ -6,6 +6,10 @@
with lib; with lib;
with builtins; let with builtins; let
cfg = config.vim.tabline.nvimBufferline; cfg = config.vim.tabline.nvimBufferline;
self = import ./nvim-bufferline.nix {
inherit lib;
};
mappings = self.options.vim.tabline.nvimBufferline.mappings;
in { in {
config = mkIf cfg.enable ( config = mkIf cfg.enable (
let let
@ -23,25 +27,18 @@ in {
"bufdelete-nvim" "bufdelete-nvim"
]; ];
vim.maps.normal = { vim.maps.normal = mkMerge [
"<silent><leader>bn" = {action = ":BufferLineCycleNext<CR>";}; (mkLuaBinding cfg.mappings.closeCurrent "require(\"bufdelete\").bufdelete" mappings.closeCurrent.description)
"<silent><leader>bp" = {action = ":BufferLineCyclePrev<CR>";}; (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext<CR>" mappings.cycleNext.description)
"<silent><leader>bc" = {action = ":BufferLinePick<CR>";}; (mkBinding cfg.mappings.cycleNext ":BufferLineCycleNext<CR>" mappings.cycleNext.description)
"<silent><leader>bse" = {action = ":BufferLineSortByExtension<CR>";}; (mkBinding cfg.mappings.cyclePrevious ":BufferLineCyclePrev<CR>" mappings.cyclePrevious.description)
"<silent><leader>bsd" = {action = ":BufferLineSortByDirectory<CR>";}; (mkBinding cfg.mappings.pick ":BufferLinePick<CR>" mappings.pick.description)
"<silent><leader>bsi" = {action = ":lua require'bufferline'.sort_buffers_by(function (buf_a, buf_b) return buf_a.id < buf_b.id end)<CR>";}; (mkBinding cfg.mappings.sortByExtension ":BufferLineSortByExtension<CR>" mappings.sortByExtension.description)
"<silent><leader>bmn" = {action = ":BufferLineMoveNext<CR>";}; (mkBinding cfg.mappings.sortByDirectory ":BufferLineSortByDirectory<CR>" mappings.sortByDirectory.description)
"<silent><leader>bmp" = {action = ":BufferLineMovePrev<CR>";}; (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)
"<silent><leader>b1" = {action = "<Cmd>BufferLineGoToBuffer 1<CR>";}; (mkBinding cfg.mappings.moveNext ":BufferLineMoveNext<CR>" mappings.moveNext.description)
"<silent><leader>b2" = {action = "<Cmd>BufferLineGoToBuffer 2<CR>";}; (mkBinding cfg.mappings.movePrevious ":BufferLineMovePrev<CR>" mappings.movePrevious.description)
"<silent><leader>b3" = {action = "<Cmd>BufferLineGoToBuffer 3<CR>";}; ];
"<silent><leader>b4" = {action = "<Cmd>BufferLineGoToBuffer 4<CR>";};
"<silent><leader>b5" = {action = "<Cmd>BufferLineGoToBuffer 5<CR>";};
"<silent><leader>b6" = {action = "<Cmd>BufferLineGoToBuffer 6<CR>";};
"<silent><leader>b7" = {action = "<Cmd>BufferLineGoToBuffer 7<CR>";};
"<silent><leader>b8" = {action = "<Cmd>BufferLineGoToBuffer 8<CR>";};
"<silent><leader>b9" = {action = "<Cmd>BufferLineGoToBuffer 9<CR>";};
};
vim.luaConfigRC.nvimBufferline = nvim.dag.entryAnywhere '' vim.luaConfigRC.nvimBufferline = nvim.dag.entryAnywhere ''
require("bufferline").setup{ require("bufferline").setup{

View file

@ -1,11 +1,19 @@
{ {lib, ...}:
config,
lib,
...
}:
with lib; with lib;
with builtins; { with builtins; {
options.vim.tabline.nvimBufferline = { options.vim.tabline.nvimBufferline = {
mappings = {
closeCurrent = mkMappingOption "Close buffer" null;
cycleNext = mkMappingOption "Next buffer" "<leader>bn";
cyclePrevious = mkMappingOption "Previous buffer" "<leader>bp";
pick = mkMappingOption "Pick buffer" "<leader>bc";
sortByExtension = mkMappingOption "Sort buffers by extension" "<leader>bse";
sortByDirectory = mkMappingOption "Sort buffers by directory" "<leader>bsd";
sortById = mkMappingOption "Sort buffers by ID" "<leader>bsi";
moveNext = mkMappingOption "Move next buffer" "<leader>bmn";
movePrevious = mkMappingOption "Move previous buffer" "<leader>bmp";
};
enable = mkEnableOption "Enable nvim-bufferline-lua as a bufferline"; enable = mkEnableOption "Enable nvim-bufferline-lua as a bufferline";
}; };
} }