The popular buffer line plugin nowadays is akinsho/bufferline, but I feel that it is too heavy and not visually appealing. For example, it can integrate with LSP and switch between various tab/buffer modes, but not everyone needs that. Also, the order is fixed. In short, I want to reinvent the wheel: fzdwx/bufline.nvim
To define a tabline in nvim, you can use vim.opt.tabline=xxx
. For example, the following code easily implements a buffer line:
function _G.qweqweqwe()
return "this is my line"
end
-- config
vim.opt.tabline = "%!v:lua.qweqweqwe()"
Then it is easy to think of the following:
- Get all buffers
- Get information about the corresponding files of the buffers
- For example, the file name
- Display file icon (supported by nvim-tree/nvim-web-devicons)
- Support highlighting
I won't go into detail on how to implement it, but if you are interested, you can check out: fzdwx/bufline.nvim. Currently, all content can be customized:
M.folder -- The input is the number of buffers, and it should return Group: {hl,str}
M.dirName -- The input is the current buffer id, and it should return Group
M.devicon -- The input is the current buffer id, "Sel/NoSel" (whether it is selected), and it should return Group
M.title -- The input is the current buffer id, "Sel/NoSel" (whether it is selected), and it should return Group
M.modified -- The input is the current buffer id, and it should return str
M.separator -- It should return Group
-- The following two methods can also be customized, and the user needs to ensure their correctness
M.cell -- Information for each buffer, the input is the current buffer id and the currently selected buffer id, and it should return a list of groups
M.bufline -- Construct the entire bufline
str
is the specific content, and hl
is the tag for highlighting. For example, BufLineFolder
currently supports:
BufLineTitleSel
BufLineTitleNoSel
BufLineFill
BufLine
BufLineFolder
These highlighting tags do not have default settings and need to be customized by the user. For example:
vim.cmd([[au ColorScheme * hi BufLineTitleSel gui=none guibg='#282C34' guifg='#5C6370']])
When setting the highlighting, there was a problem where icons with a background color and icons without one would have different sizes. In the end, I had no choice but to make them all have colors, just like the bufferline.
Using in lazy:
{
"fzdwx/bufline.nvim",
event = "BufEnter",
dependencies = {
"nvim-tree/nvim-web-devicons",
},
config = function()
local buf = require("bufline")
buf.setup({
-- Custom separator
separator = function()
return {
str = '',
hl = ""
}
end
})
end,
},