From adcdd78525d92cc3d95285dc7d336035a79d628a Mon Sep 17 00:00:00 2001 From: punkfairie Date: Fri, 29 Nov 2024 18:08:02 -0800 Subject: [PATCH] feat: bufferline.nvim --- nix/neovim-overlay.nix | 1 + nvim/lua/icons.lua | 8 +++ nvim/lua/plugins/ui/bufferline-nvim.lua | 79 +++++++++++++++++++++++++ nvim/lua/plugins/ui/init.lua | 1 + 4 files changed, 89 insertions(+) create mode 100644 nvim/lua/icons.lua create mode 100644 nvim/lua/plugins/ui/bufferline-nvim.lua diff --git a/nix/neovim-overlay.nix b/nix/neovim-overlay.nix index c73cb35..0e0f77d 100644 --- a/nix/neovim-overlay.nix +++ b/nix/neovim-overlay.nix @@ -35,6 +35,7 @@ with final.pkgs.lib; let # UI mini-icons + bufferline-nvim ]; extraPackages = with pkgs; [ diff --git a/nvim/lua/icons.lua b/nvim/lua/icons.lua new file mode 100644 index 0000000..5c614c9 --- /dev/null +++ b/nvim/lua/icons.lua @@ -0,0 +1,8 @@ +return { + diagnostics = { + Error = ' ', + Warn = ' ', + Hint = ' ', + Info = ' ', + }, +} diff --git a/nvim/lua/plugins/ui/bufferline-nvim.lua b/nvim/lua/plugins/ui/bufferline-nvim.lua new file mode 100644 index 0000000..4872654 --- /dev/null +++ b/nvim/lua/plugins/ui/bufferline-nvim.lua @@ -0,0 +1,79 @@ +return { + 'bufferline.nvim', + event = 'DeferredUIEnter', + keys = { + { 'bp', 'BufferLineTogglePin', desc = 'Toggle pin' }, + { + 'bP', + 'BufferLineGroupClose ungrouped', + desc = 'Delete non-pinned buffers', + }, + { + 'br', + 'BufferLineCloseRight', + desc = 'Delete buffers to the right', + }, + { + 'bl', + 'BufferLineCloseLeft', + desc = 'Delete buffers to the left', + }, + { '', 'BufferLineCyclePrev', desc = 'Previous buffer' }, + { '', 'BufferLineCycleNext', desc = 'Next buffer' }, + { '[b', 'BufferLineCyclePrev', desc = 'Previous buffer' }, + { ']b', 'BufferLineCycleNext', desc = 'Next buffer' }, + { '[B', 'BufferLineMovePrev', desc = 'Move buffer left' }, + { ']B', 'BufferLineMoveNext', desc = 'Move buffer right' }, + }, + before = function() + require('lz.n').trigger_load('mini.icons') + end, + after = function() + require('bufferline').setup({ + options = { + always_show_bufferline = true, + + close_command = function(n) + Snacks.bufdelete(n) + end, + right_mouse_command = function(n) + Snacks.bufdelete(n) + end, + + diagnostics = 'nvim_lsp', + diagnostics_indicator = function(_, _, diag) + local icons = require('icons').diagnostics + local ret = (diag.error and icons.Error .. diag.error .. ' ' or '') + .. (diag.warning and icons.Warn .. diag.warning or '') + + return vim.trim(ret) + end, + + offsets = { + { + filetype = 'neo-tree', + text = 'Explorer', + highlight = 'Directory', + text_align = 'center', + }, + }, + + get_element_icon = function(elem) + local icon, hl, _ = + require('mini.icons').get('filetype', elem.filetype) + + return icon, hl + end, + }, + }) + + vim.api.nvim_create_autocmd({ 'BufAdd', 'BufDelete' }, { + desc = 'Fix bufferline when restoring a session', + callback = function() + vim.schedule(function() + pcall(nvim_bufferline) + end) + end, + }) + end, +} diff --git a/nvim/lua/plugins/ui/init.lua b/nvim/lua/plugins/ui/init.lua index 062e643..6104e65 100644 --- a/nvim/lua/plugins/ui/init.lua +++ b/nvim/lua/plugins/ui/init.lua @@ -1,5 +1,6 @@ local req = require('lib.marleyvim').localRequire('plugins.ui') return { + req('bufferline-nvim'), req('mini-icons'), }