You can use the 'tabline'
setting for this. Here's an example adapted from :help setting-tabline
:
set tabline=%!MyTabLine()
" Set the entire tabline
function! MyTabLine()
let s = ''
for i in range(tabpagenr('$'))
" select the highlighting
if i + 1 == tabpagenr()
let s .= '%#TabLineSel#'
else
let s .= '%#TabLine#'
endif
" set the tab page number (for mouse clicks)
let s .= '%' . (i + 1) . 'T'
" the label is made by MyTabLabel()
let s .= ' %{MyTabLabel(' . (i + 1) . ')} '
endfor
" after the last tab fill with TabLineFill and reset tab page nr
let s .= '%#TabLineFill#%T'
" right-align the label to close the current tab page
if tabpagenr('$') > 1
let s .= '%=%#TabLine#%999Xclose'
endif
return s
endfunction
" Set the label for a single tab
function! MyTabLabel(n)
" This is run in the scope of the active tab, so t:name
" won't work.
let l:tabname = gettabvar(a:n, 'name', '')
" This variable exists!
if l:tabname != ''
return l:tabname
endif
" If it's not found fall back to the buffer name
let buflist = tabpagebuflist(a:n)
let winnr = tabpagewinnr(a:n)
let l:bname = bufname(buflist[winnr - 1])
" Unnamed buffer, scratch buffer, etc. Could be more detailed.
if l:bname == ''
let l:bname = '[No Name]'
endif
return l:bname
endfunction
The key is in the MyTabLabel()
function. If the tab-local t:name
variable exists, we use that. Otherwise we default back to the currently active buffer name.
To name the tab label, simple set the t:name
variable for that tab. For the currently active tab:
:let t:name = 'Session one'
or for a specific tab nr:
:call settabvar(3, 'name', 'Session four')
:help setting-tabline
should help