Repository navigation
Expand file tree
/
Copy pathbufferline.lua
More file actions
60 lines (60 loc) · 2.41 KB
/
Copy pathbufferline.lua
File metadata and controls
60 lines (60 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- Buffer line configuration
-- Shows open buffers at the top of the screen
return {
"akinsho/bufferline.nvim",
opts = {
options = {
always_show_bufferline = false,
show_buffer_close_icons = false,
show_close_icon = false,
},
},
config = function(_, opts)
require("bufferline").setup(opts)
-- bufferline restores pins on SessionLoadPost, which fires before VeryLazy on :restart
if vim.v.this_session ~= "" and (vim.g.BufferlinePinnedBuffers or "") ~= "" then
local groups = require("bufferline.groups")
for _, path in ipairs(vim.split(vim.g.BufferlinePinnedBuffers, ",")) do
local buf = vim.fn.bufnr(path)
if buf ~= -1 then
groups.add_element("pinned", { id = buf })
end
end
require("bufferline.ui").refresh()
end
-- Workaround: bufferline keeps pinned buffer ids in its manual_groupings
-- table even after the buffer is wiped out (e.g. via Snacks.bufdelete).
-- persist_pinned_buffers then calls nvim_buf_get_name on the dead id and
-- errors with "Invalid buffer id" on the next BufferLineTogglePin.
vim.api.nvim_create_autocmd("BufWipeout", {
group = vim.api.nvim_create_augroup("bufferline_pin_cleanup", { clear = true }),
callback = function(ev)
require("bufferline.groups").remove_id_from_manual_groupings(ev.buf)
end,
})
end,
keys = {
{ "<A-Left>", "<cmd>BufferLineCyclePrev<cr>", desc = "Move to previous buffer" },
{ "<A-Right>", "<cmd>BufferLineCycleNext<cr>", desc = "Move to next buffer" },
{ "<A-,>", "<cmd>BufferLineMovePrev<cr>", desc = "Re-order to previous buffer" },
{ "<A-.>", "<cmd>BufferLineMoveNext<cr>", desc = "Re-order to next buffer" },
{ "<A-p>", "<cmd>BufferLineTogglePin<cr>", desc = "Toggle Pin" },
{ "<leader>bP", false },
{
"<leader>bw",
function()
-- BufferLineGroupClose bypasses close_command and uses a raw bdelete!,
-- which closes the window showing the buffer (e.g. when focused on the
-- explorer sidebar). Use Snacks.bufdelete so windows keep a buffer.
local groups = require("bufferline.groups")
Snacks.bufdelete({
filter = function(buf)
return not groups._is_pinned({ id = buf })
end,
})
end,
desc = "Delete Non-Pinned Buffers",
},
{ "<leader>bW", "<cmd>BufferLineCloseOthers<cr>", desc = "Delete All Buffers" },
},
}