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>
This commit is contained in:
Tokubara 2022-02-07 23:26:25 +08:00 committed by GitHub
parent 2bddaf0508
commit d52ff470de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 3 deletions

View File

@ -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 You can also completely move your statusline to a tabline by configuring
`lualine.tabline` and disabling `lualine.sections` and `lualine.inactive_sections`: `lualine.tabline` and disabling `lualine.sections` and `lualine.inactive_sections`:

View File

@ -645,10 +645,40 @@ more traditional tabline/bufferline.
< <
You can also completely move your statusline to a tabline by configuring *lualine-Buffers*
`lualine.tabline` and disabling `lualine.sections` and
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
<
Its useful when youre 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`: `lualine.inactive_sections`:
> >
tabline = { tabline = {
...... ......

View File

@ -167,6 +167,17 @@ vim.cmd([[
function! LualineSwitchTab(tabnr, mouseclicks, mousebutton, modifiers) function! LualineSwitchTab(tabnr, mouseclicks, mousebutton, modifiers)
execute a:tabnr . "tabnext" execute a:tabnr . "tabnext"
endfunction endfunction
function! LualineRenameTab(...)
if a:0 == 1
let t:tabname = a:1
else
unlet t:tabname
end
redrawtabline
endfunction
command! -nargs=? LualineRenameTab call LualineRenameTab("<args>")
]]) ]])
return M return M

View File

@ -14,6 +14,10 @@ end
--- of the tab. --- of the tab.
---@return string ---@return string
function Tab:label() 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 buflist = vim.fn.tabpagebuflist(self.tabnr)
local winnr = vim.fn.tabpagewinnr(self.tabnr) local winnr = vim.fn.tabpagewinnr(self.tabnr)
local bufnr = buflist[winnr] local bufnr = buflist[winnr]