nvim/init.tabline.vim

70 lines
1.8 KiB
VimL
Raw Permalink Normal View History

2019-09-13 14:27:38 +00:00
" Rename tabs to show tab number.
" based on:
" http://stackoverflow.com/questions/5927952/whats-implementation-of-vims-default-tabline-function
function! MyTabLine() "{{{
let l:customtabline = ''
let l:currenttabnum = tabpagenr()
let l:lasttabnumber = tabpagenr('$')
let l:tabnumber = 1
while l:tabnumber <= l:lasttabnumber
let l:buflist = tabpagebuflist(l:tabnumber)
let l:winnr = tabpagewinnr(l:tabnumber)
if l:lasttabnumber > 1
let l:customtabline .= '%' . l:tabnumber . 'T'
let l:customtabline .= (l:tabnumber == l:currenttabnum ? '%1*' : '%2*')
let l:customtabline .= (l:tabnumber == l:currenttabnum ? '%#TabLineNumSel#' : '%#TabLineNum#')
let l:customtabline .= ' ' . l:tabnumber . ' '
let l:customtabline .= (l:tabnumber == l:currenttabnum ? '%#TabLineItemSel#' : '%#TabLineItem#')
endif
let l:bufnr = l:buflist[l:winnr - 1]
let l:file = bufname(l:bufnr)
let l:buftype = getbufvar(l:bufnr, '&buftype')
if l:buftype ==# 'help'
let l:file = 'help:' . fnamemodify(l:file, ':t:r')
elseif l:buftype ==# 'quickfix'
let l:file = 'quickfix'
elseif l:buftype ==# 'nofile'
if l:file =~# '\/.'
let l:file = substitute(l:file, '.*\/\ze.', '', '')
endif
else
let l:file = fnamemodify(l:file, ':p:t')
endif
if l:file ==# ''
let l:file = "''"
endif
2021-09-07 12:44:51 +00:00
let l:customtabline .= l:file . '%T%#TabLineFill# '
2019-09-13 14:27:38 +00:00
let l:tabnumber = l:tabnumber + 1
endwhile
let l:customtabline .= '%T%#TabLineFill#%='
let l:customtabline .= '%#TabLineItem# %{getcwd()}% '
if exists('*ObsessionStatus')
2020-07-31 11:48:16 +00:00
let l:customtabline .= "%#TabLineItem# %{ObsessionStatus(fnamemodify(v:this_session,':t'),'---')} %*"
2019-09-13 14:27:38 +00:00
endif
return l:customtabline
endfunction
"}}}
set tabline=%!MyTabLine()
set showtabline=2
" vim: set foldmethod=marker: