local M = {} -- Helper to get label for each tab page local function tab_label(n) local buflist = vim.fn.tabpagebuflist(n) local winnr = vim.fn.tabpagewinnr(n) local bufname = vim.fn.bufname(buflist[winnr]) if bufname == '' then bufname = '[No Name]' else bufname = vim.fn.fnamemodify(bufname, ':t') -- tail only end -- Determine window count reliably local win_count = vim.fn.tabpagewinnr(n, '$') -- Check if any buffer in the tab is modified local modified = false for _, buf in ipairs(buflist) do if vim.fn.getbufvar(buf, '&modified') == 1 then modified = true break end end -- Construct label according to rules: -- single clean: File -- single edited: +:File -- multi clean: 2:File -- multi edited: 2+:File if win_count == 1 then if modified then bufname = '+:' .. bufname end else local prefix = tostring(win_count) if modified then prefix = prefix .. '+' end bufname = prefix .. ':' .. bufname end -- Truncate overly long names if #bufname > 20 then bufname = bufname:sub(1, 17) .. '…' end return bufname end -- Main tabline builder function M.tabline() local s = '' local num_tabs = vim.fn.tabpagenr('$') for i = 1, num_tabs do -- Highlight current tab if i == vim.fn.tabpagenr() then s = s .. '%#TabLineSel#' else s = s .. '%#TabLine#' end -- Mouse click target s = s .. '%' .. i .. 'T' -- Label s = s .. ' ' .. tab_label(i) .. ' ' end -- Fill empty space s = s .. '%#TabLineFill#%T' return s end function M.setup() vim.o.showtabline = 1 vim.o.tabline = "%!v:lua.require'plugins.tabline'.tabline()" end return M