From c0a6c5848a1e91081f3356270fadfb385e592461 Mon Sep 17 00:00:00 2001 From: Roman Date: Sun, 28 Jun 2026 13:34:02 +0200 Subject: [PATCH] Custom tabline --- .../nvim/lua/romanzy/custom/tabline.lua | 71 +++++++++++++++++++ nvim/.config/nvim/lua/romanzy/options.lua | 1 + nvim/.config/nvim/lua/romanzy/plugins.lua | 3 + 3 files changed, 75 insertions(+) create mode 100644 nvim/.config/nvim/lua/romanzy/custom/tabline.lua diff --git a/nvim/.config/nvim/lua/romanzy/custom/tabline.lua b/nvim/.config/nvim/lua/romanzy/custom/tabline.lua new file mode 100644 index 0000000..46493e2 --- /dev/null +++ b/nvim/.config/nvim/lua/romanzy/custom/tabline.lua @@ -0,0 +1,71 @@ +local M = {} + +local function truncate_label(label, max_width) + if vim.fn.strdisplaywidth(label) <= max_width then + return label + end + + return vim.fn.strcharpart(label, 0, max_width - 1) .. "…" +end + +local function terminal_label(bufnr) + local term_title = vim.b[bufnr].term_title + if type(term_title) == "string" and term_title ~= "" then + local cmd = vim.fn.fnamemodify(term_title:match("^%S+") or "", ":t") + if cmd ~= "" then + return cmd + end + end + + local bufname = vim.api.nvim_buf_get_name(bufnr) + local cmd = bufname:match("term://.*:(.+)$") + if cmd then + local first_word = vim.split(cmd, " ", { plain = true })[1] or "" + local basename = vim.fn.fnamemodify(first_word, ":t") + if basename ~= "" then + return basename + end + end + + return "terminal" +end + +local function tab_label(tabnr) + local buflist = vim.fn.tabpagebuflist(tabnr) + local winnr = vim.fn.tabpagewinnr(tabnr) + local bufnr = buflist[winnr] + local label + + if vim.bo[bufnr].buftype == "terminal" then + label = terminal_label(bufnr) + else + local bufname = vim.api.nvim_buf_get_name(bufnr) + label = bufname == "" and "[No Name]" or vim.fn.fnamemodify(bufname, ":t") + end + + if vim.bo[bufnr].modified then + label = label .. " +" + end + + return truncate_label(label, 18) +end + +function M.render() + local current = vim.fn.tabpagenr() + local last = vim.fn.tabpagenr("$") + local parts = {} + + for index = 1, last do + parts[#parts + 1] = index == current and "%#TabLineSel#" or "%#TabLine#" + parts[#parts + 1] = "%" .. index .. "T" + parts[#parts + 1] = " " .. index .. " " .. tab_label(index) .. " " + end + + parts[#parts + 1] = "%#TabLineFill#%T" + + return table.concat(parts) +end + +_G.RomanzyTabline = M.render + +return M diff --git a/nvim/.config/nvim/lua/romanzy/options.lua b/nvim/.config/nvim/lua/romanzy/options.lua index 95c94c2..67fa15d 100644 --- a/nvim/.config/nvim/lua/romanzy/options.lua +++ b/nvim/.config/nvim/lua/romanzy/options.lua @@ -32,6 +32,7 @@ o.incsearch = true -- Updates search matches as you type. o.updatetime = 50 -- Reduces idle delay for swap and CursorHold events. o.spelllang = { "en_us" } -- Uses US English for spell checking. o.shell = "bash" -- Runs shell commands through bash. +o.tabline = "%!v:lua.RomanzyTabline()" -- Shows native tabs with custom labels. -- Only show the invisible characters inside the code editing buffers vim.cmd([[autocmd BufWinEnter * if &buftype != '' | setlocal nolist | endif]]) diff --git a/nvim/.config/nvim/lua/romanzy/plugins.lua b/nvim/.config/nvim/lua/romanzy/plugins.lua index 2f75c6a..af06b4a 100644 --- a/nvim/.config/nvim/lua/romanzy/plugins.lua +++ b/nvim/.config/nvim/lua/romanzy/plugins.lua @@ -5,3 +5,6 @@ require("romanzy.plugins.telescope") require("romanzy.plugins.nvim-treesitter") require("romanzy.plugins.lsp") -- require("romanzy.plugins.header42") + +-- custom "plugins" +require("romanzy.custom.tabline")