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

110 lines
3 KiB
Lua
Raw Normal View History

2024-11-29 18:08:02 -08:00
return {
'bufferline.nvim',
event = 'DeferredUIEnter',
keys = {
2024-12-01 17:10:02 -08:00
{
'<LEADER>bp',
'<CMD>BufferLineTogglePin<CR>',
desc = 'toggle buffer pin',
},
2024-11-29 18:08:02 -08:00
{
'<LEADER>bP',
'<CMD>BufferLineGroupClose ungrouped<CR>',
2024-12-01 17:10:02 -08:00
desc = 'delete non-pinned buffers',
2024-11-29 18:08:02 -08:00
},
{
'<LEADER>br',
'<CMD>BufferLineCloseRight<CR>',
2024-12-01 17:10:02 -08:00
desc = 'delete buffers to the right',
2024-11-29 18:08:02 -08:00
},
{
'<LEADER>bl',
'<CMD>BufferLineCloseLeft<CR>',
2024-12-01 17:10:02 -08:00
desc = 'delete buffers to the left',
2024-11-29 18:08:02 -08:00
},
2024-12-01 17:10:02 -08:00
{ '<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' },
2024-11-29 18:08:02 -08:00
},
before = function()
2024-12-01 17:10:02 -08:00
require('lz.n').trigger_load({ 'mini.icons', 'which-key.nvim' })
2024-11-30 11:31:11 -08:00
if vim.g.colors_name == 'rose-pine' then
require('lz.n').trigger_load('rose-pine')
end
2024-11-29 18:08:02 -08:00
end,
after = function()
2024-11-30 11:31:11 -08:00
local opts = {
2024-11-29 18:08:02 -08:00
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,
},
2024-11-30 11:31:11 -08:00
}
if vim.g.colors_name == 'rose-pine' then
opts.highlights = require('rose-pine.plugins.bufferline')
end
require('bufferline').setup(opts)
2024-11-29 18:08:02 -08:00
vim.api.nvim_create_autocmd({ 'BufAdd', 'BufDelete' }, {
desc = 'Fix bufferline when restoring a session',
callback = function()
vim.schedule(function()
pcall(nvim_bufferline)
end)
end,
})
2024-12-01 17:10:02 -08:00
local colors = require('colors')
local mkKey = MarleyVim.wkSpec(colors.buffers)
require('which-key').add({
2024-12-04 21:41:30 -08:00
mkKey('<LEADER>bp', nil, ''),
mkKey('<LEADER>bP', nil, '󰐄'),
mkKey('<LEADER>br', nil, ''),
mkKey('<LEADER>bl', nil, ''),
mkKey('<S-H>', nil, ''),
mkKey('<S-L>', nil, ''),
mkKey('[b', nil, ''),
mkKey(']b', nil, ''),
mkKey('[B', nil, ''),
mkKey(']B', nil, ''),
2024-12-01 17:10:02 -08:00
})
2024-11-29 18:08:02 -08:00
end,
}