diff --git a/init.lua b/init.lua index 1c931a9..9a08766 100644 --- a/init.lua +++ b/init.lua @@ -21,6 +21,7 @@ require('config.autocmds') require('config.clipboard') require('config.terminal') require('custom.navigation') +require('custom.tabline').setup() require('lazy').setup({ spec = { { import = 'plugins' } }, install = { missing = false }, diff --git a/lua/custom/tabline.lua b/lua/custom/tabline.lua new file mode 100644 index 0000000..411024a --- /dev/null +++ b/lua/custom/tabline.lua @@ -0,0 +1,86 @@ +-- ~/.config/nvim/lua/custom/tabline.lua +-- Custom Lua tabline with proper modified/unsaved and window count handling + +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'custom.tabline'.tabline()" +end + +return M diff --git a/lua/plugins/colorscheme.lua b/lua/plugins/colorscheme.lua index 83aa635..e51bbe0 100644 --- a/lua/plugins/colorscheme.lua +++ b/lua/plugins/colorscheme.lua @@ -12,9 +12,13 @@ return { highlights = function(c, tool) c.bg_float = tool(152) return { + ModeMsg = { fg = c.yellow, bg = c.none, bold = true }, WinSeparator = { fg = c.outline, bg = c.base }, StatusLine = { fg = c.outline, bg = c.base }, StatusLineNC = { fg = c.text, bg = c.base, bold = true }, + TabLine = { fg = c.muted, bg = c.none }, + TabLineSel = { fg = c.text, bg = c.none, bold = true }, + TabLineFill = { fg = c.outline_light, bg = c.none }, } end, })