From d52ff470de040cd9c5d1b2a7817cea93b53d5338 Mon Sep 17 00:00:00 2001 From: Tokubara <32409331+Tokubara@users.noreply.github.com> Date: Mon, 7 Feb 2022 23:26:25 +0800 Subject: [PATCH] feature to rename tabs (#574) * (feat) add rename * remove tabname if LualineRenameTab is ran without args * document LualineRenameTab Co-authored-by: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> --- README.md | 18 ++++++++++++++ doc/lualine.txt | 36 +++++++++++++++++++++++++--- lua/lualine/components/tabs/init.lua | 11 +++++++++ lua/lualine/components/tabs/tab.lua | 4 ++++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a795651..ccf9589 100644 --- a/README.md +++ b/README.md @@ -617,6 +617,24 @@ tabline = { } ``` +#### Buffers +Shows currently open buffers. Like bufferline . See +[buffers options](#buffers-component-options) +for all builtin behaviors of buffers component. + +#### Tabs +Shows currently open tab. Like usual tabline. See +[tabs options](#tabs-component-options) +for all builtin behaviors of tabs component. +You can also use `:LualineRenameTab` to set a name for a tabpage. +For example: +```vim +:LualineRenameTab Project_K +```` +It's useful when you're using rendering mode 2/3 in tabs. +To unname a tablage run `:LualineRenameTab` without argument. + +#### Tabline as statusline You can also completely move your statusline to a tabline by configuring `lualine.tabline` and disabling `lualine.sections` and `lualine.inactive_sections`: diff --git a/doc/lualine.txt b/doc/lualine.txt index ff24d62..0e9d82f 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -645,9 +645,39 @@ more traditional tabline/bufferline. < -You can also completely move your statusline to a tabline by configuring -`lualine.tabline` and disabling `lualine.sections` and -`lualine.inactive_sections`: + *lualine-Buffers* + +Buffers Shows currently open buffers. Like + bufferline. See + |lualine-buffers-options| for all + builtin behaviors of buffers component. + + + *lualine-Tabs* + +Tabs Shows currently open tab. Like usual + tabline. See |lualine-tabs-options| for + all builtin behaviors of tabs component. + You can also use `:LualineRenameTab` to + set a name for a tabpage. For example: + + +> + :LualineRenameTab Project_K +< + + +It’s useful when you’re using rendering mode 2/3 in tabs. To unname a +tablage run `:LualineRenameTab` without argument. + + *lualine-Tabline-as-statusline* + +Tabline as statusline You can also completely move your + statusline to a tabline by configuring + `lualine.tabline` and disabling + `lualine.sections` and + `lualine.inactive_sections`: + > tabline = { diff --git a/lua/lualine/components/tabs/init.lua b/lua/lualine/components/tabs/init.lua index 84d4e55..6c21716 100644 --- a/lua/lualine/components/tabs/init.lua +++ b/lua/lualine/components/tabs/init.lua @@ -167,6 +167,17 @@ vim.cmd([[ function! LualineSwitchTab(tabnr, mouseclicks, mousebutton, modifiers) execute a:tabnr . "tabnext" endfunction + + function! LualineRenameTab(...) + if a:0 == 1 + let t:tabname = a:1 + else + unlet t:tabname + end + redrawtabline + endfunction + + command! -nargs=? LualineRenameTab call LualineRenameTab("") ]]) return M diff --git a/lua/lualine/components/tabs/tab.lua b/lua/lualine/components/tabs/tab.lua index fe9cc7c..350aeb2 100644 --- a/lua/lualine/components/tabs/tab.lua +++ b/lua/lualine/components/tabs/tab.lua @@ -14,6 +14,10 @@ end --- of the tab. ---@return string function Tab:label() + local custom_tabname = vim.t[self.tabnr].tabname + if custom_tabname and custom_tabname ~= '' then + return custom_tabname + end local buflist = vim.fn.tabpagebuflist(self.tabnr) local winnr = vim.fn.tabpagewinnr(self.tabnr) local bufnr = buflist[winnr]