function _G.MyTabLine()
local s = {}
local cur = vim.fn.tabpagenr()
local last = vim.fn.tabpagenr("$")
for i = 1, last do
local is_cur = (i == cur)
-- Highlight group for the tab chunk
table.insert(s, is_cur and "%#TabLineSel#" or "%#TabLine#")
-- You had a second highlight decision that used Title for inactive
table.insert(s, is_cur and "%#TabLineSel#" or "%#Title#")
-- Click target for mouse (tab page number)
table.insert(s, ("%%%dT "):format(i))
-- Page number label
table.insert(s, tostring(i))
-- Collect buffer names + modified counter
local names = {}
local modified = 0
local buflist = vim.fn.tabpagebuflist(i)
for _, b in ipairs(buflist) do
local buftype = vim.fn.getbufvar(b, "&buftype")
local modifiable = vim.fn.getbufvar(b, "&modifiable") == 1
local is_modified = vim.fn.getbufvar(b, "&modified") == 1
if buftype == "help" then
-- intentionally skipped
elseif buftype == "quickfix" then
-- intentionally skipped
elseif modifiable then
local name = vim.fn.bufname(b)
local tail = (name ~= "" and vim.fn.fnamemodify(name, ":t")) or "[No Name]"
table.insert(names, tail)
end
if is_modified then
modified = modified + 1
end
end
-- Modified marker
if modified > 0 then
table.insert(s, "+")
end
-- Back to tab highlight for the buffer-name part
table.insert(s, is_cur and " %#TabLineSel#" or " %#TabLine#")
-- Buffer names (or [New])
if #names == 0 then
table.insert(s, "[New]")
else
table.insert(s, table.concat(names, ", "))
end
table.insert(s, " ")
end
-- Fill + end click target
table.insert(s, "%#TabLineFill#%T")
return table.concat(s)
end