Added custom function for tabline not to display the 'X'/Close symbol on top right corner. Additionally, given it some Kanagawa theme compatible native tabline look.

This commit is contained in:
psychhim
2025-09-22 05:50:04 +05:30
parent 00885ca41c
commit 62760d6132
2 changed files with 67 additions and 1 deletions

View File

@@ -812,5 +812,71 @@ require('luasnip.loaders.from_vscode').lazy_load()
-- Theme
require('kanagawa').setup { transparent = true }
vim.cmd [[colorscheme kanagawa]]
-- Custom native-looking tabline that matches Kanagawa theme
vim.o.showtabline = 1
_G.tab_offset = 1
local max_visible_tabs = 8 -- maximum number of tabs visible at once
function _G.Tabline()
local current_tab = vim.fn.tabpagenr()
local tab_count = vim.fn.tabpagenr '$'
local win_width = vim.o.columns
local tab_width = math.floor(win_width / max_visible_tabs) -- FIXED width
local tabs = {}
for i = 1, tab_count do
local buflist = vim.fn.tabpagebuflist(i)
local winnr = vim.fn.tabpagewinnr(i)
local bufname = vim.fn.bufname(buflist[winnr])
if bufname == '' then
bufname = '[No Name]'
end
local modified = vim.fn.getbufvar(buflist[winnr], '&mod') == 1 and '' or ''
local label = i .. ': ' .. vim.fn.fnamemodify(bufname, ':t') .. modified
-- truncate/pad to fixed tab_width
if #label > tab_width - 2 then
label = label:sub(1, tab_width - 3) .. ''
end
label = label .. string.rep(' ', tab_width - #label)
tabs[i] = (i == current_tab and '%#TabLineSel#' or '%#TabLine#') .. label
end
-- scrolling logic to keep active tab visible
local start_index = _G.tab_offset
if current_tab < start_index then
start_index = current_tab
elseif current_tab >= start_index + max_visible_tabs then
start_index = current_tab - max_visible_tabs + 1
end
_G.tab_offset = start_index
-- select visible tabs
local visible_tabs = {}
for i = start_index, math.min(start_index + max_visible_tabs - 1, tab_count) do
table.insert(visible_tabs, tabs[i])
end
-- scrolling arrows
local left_arrow = start_index > 1 and '< ' or ' '
local right_arrow = start_index + max_visible_tabs - 1 < tab_count and ' >' or ' '
return '%#TabLine#' .. left_arrow .. table.concat(visible_tabs, '') .. right_arrow .. '%#TabLineFill#'
end
vim.o.tabline = '%!v:lua.Tabline()'
-- adjust offset if tabs are closed
vim.api.nvim_create_autocmd({ 'TabClosed' }, {
callback = function()
local tab_count = vim.fn.tabpagenr '$'
if _G.tab_offset > tab_count then
_G.tab_offset = math.max(tab_count - max_visible_tabs + 1, 1)
end
end,
})
-- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et