There are two tablines in Vim: a "regular" tabline, and a GUI tabline.
If you're running GVim and guioptions
contains e
(this is the default) then the GUI tabline is used.
Tweaking the GUI tabline is pretty straightforward:
" use t:TabLabel if set; otherwise use the defaults
let &guitablabel='%{get(t:,"TabLabel","")}'
And then set the labels with:
call settabvar(1, "TabLabel", "Database")
call settabvar(2, "TabLabel", "Backend")
call settabvar(3, "TabLabel", "Frontend")
And so on.
However, for the regular tabline you have to compose the whole string at once, so it gets much more tricky.
The following code is loosely based on the example code from :h setting-tabline
" get some label for a single tab
function! MyTabLabel(tabarg)
" try t:TabLabel
let l:result = gettabvar(a:tabarg, "TabLabel", "")
" or active buffer name
if empty(l:result)
let l:result = bufname(winbufnr(win_getid(tabpagewinnr(a:tabarg), a:tabarg)))
endif
" or some fixed string
if empty(l:result)
let l:result = '[Noname]'
endif
" truncate the path, so (hopefully) it will not get too long
return l:result[strridx(l:result, '/') + 1 : ]
endfunction
" build the whole tabline
function! MyTabLine()
let l:result = ''
" all our tabs
for l:num in range(1, tabpagenr("$"))
" tab color
let l:result .= (l:num != tabpagenr()) ? '%#TabLine#' : '%#TabLineSel#'
" tab text
let l:result .= '%' . l:num . 'T %{MyTabLabel(' . l:num . ')} '
endfor
" space filler
let l:result .= '%#TabLineFill#%T%='
" [X] button on the right if there are several tabs
let l:result .= repeat('%#TabLine#%999X[X]', l:num > 1)
return l:result
endfunction
" setup our tabline
set tabline=%!MyTabLine()
" set sample labels
call settabvar(1, "TabLabel", "Database")
call settabvar(2, "TabLabel", "Backend")
call settabvar(3, "TabLabel", "Frontend")
And the last but not least, make sure that showtabline
is not equal to zero, or your tabline will never be shown.