marleyvim/nvim/lua/plugins/ui/bufferline-nvim.lua

109 lines
2.9 KiB
Lua

return {
'bufferline.nvim',
event = 'DeferredUIEnter',
keys = {
{
'<LEADER>bp',
'<CMD>BufferLineTogglePin<CR>',
desc = 'toggle buffer pin',
},
{
'<LEADER>bP',
'<CMD>BufferLineGroupClose ungrouped<CR>',
desc = 'delete non-pinned buffers',
},
{
'<LEADER>br',
'<CMD>BufferLineCloseRight<CR>',
desc = 'delete buffers to the right',
},
{
'<LEADER>bl',
'<CMD>BufferLineCloseLeft<CR>',
desc = 'delete buffers to the left',
},
{ '<S-H>', '<CMD>BufferLineCyclePrev<CR>', desc = 'previous buffer' },
{ '<S-L>', '<CMD>BufferLineCycleNext<CR>', desc = 'next buffer' },
{ '[b', '<CMD>BufferLineCyclePrev<CR>', desc = 'previous buffer' },
{ ']b', '<CMD>BufferLineCycleNext<CR>', desc = 'next buffer' },
{ '[B', '<CMD>BufferLineMovePrev<CR>', desc = 'move buffer left' },
{ ']B', '<CMD>BufferLineMoveNext<CR>', desc = 'move buffer right' },
},
before = function()
require('lz.n').trigger_load({ 'mini.icons', 'which-key.nvim' })
if vim.g.colors_name == 'rose-pine' then
require('lz.n').trigger_load('rose-pine')
end
end,
after = function()
local opts = {
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,
},
}
if vim.g.colors_name == 'rose-pine' then
opts.highlights = require('rose-pine.plugins.bufferline')
end
require('bufferline').setup(opts)
vim.api.nvim_create_autocmd({ 'BufAdd', 'BufDelete' }, {
desc = 'Fix bufferline when restoring a session',
callback = function()
vim.schedule(function()
pcall(nvim_bufferline)
end)
end,
})
local colors = require('colors')
local mkKey = MarleyVim.wkSpec(colors.buffers)
require('which-key').add({
mkKey('<LEADER>bp', ''),
mkKey('<LEADER>bP', '󰐄'),
mkKey('<LEADER>br', ''),
mkKey('<LEADER>bl', ''),
mkKey('<S-H>', ''),
mkKey('<S-L>', ''),
mkKey('[b', ''),
mkKey(']b', ''),
mkKey('[B', ''),
mkKey(']B', ''),
})
end,
}