tidied up and removed tab index when no more than one tab opened

This commit is contained in:
ManjaroOne666 2018-05-01 22:53:07 +01:00
parent 97cca4bf92
commit 8a6a2c5f2c
1 changed files with 38 additions and 40 deletions

View File

@ -1,70 +1,68 @@
if exists("+showtabline") if exists('+showtabline')
" Rename tabs to show tab number. " Rename tabs to show tab number.
" based on: " based on:
" http://stackoverflow.com/questions/5927952/whats-implementation-of-vims-default-tabline-function " http://stackoverflow.com/questions/5927952/whats-implementation-of-vims-default-tabline-function
function! MyTabLine() function! MyTabLine()
let s = '' let l:customtabline = ''
let t = tabpagenr() let l:currenttabnum = tabpagenr()
let i = 1 let l:lasttabnumber = tabpagenr('$')
while i <= tabpagenr('$') let l:tabnumber = 1
let buflist = tabpagebuflist(i) while l:tabnumber <= l:lasttabnumber
let winnr = tabpagewinnr(i) let l:buflist = tabpagebuflist(l:tabnumber)
let s .= '%' . i . 'T' let l:winnr = tabpagewinnr(l:tabnumber)
let s .= (i == t ? '%1*' : '%2*')
let s .= (i == t ? '%#TabNumSel#' : '%#TabNum#') if l:lasttabnumber > 1
let s .= ' ' . i let l:customtabline .= '%' . l:tabnumber . 'T'
let s .= '%#TabSeparator#:' let l:customtabline .= (l:tabnumber == l:currenttabnum ? '%1*' : '%2*')
let s .= (i == t ? '%#TabLineItemSel#' : '%#TabLineItem#')
let bufnr = buflist[winnr - 1] let l:customtabline .= (l:tabnumber == l:currenttabnum ? '%#TabNumSel#' : '%#TabNum#')
let file = bufname(bufnr) let l:customtabline .= ' ' . l:tabnumber
let buftype = getbufvar(bufnr, '&buftype') let l:customtabline .= '%#TabSeparator#:'
let l:customtabline .= (l:tabnumber == l:currenttabnum ? '%#TabLineItemSel#' : '%#TabLineItem#')
endif
if buftype == 'help' let l:bufnr = l:buflist[l:winnr - 1]
let file = 'help:' . fnamemodify(file, ':t:r') let l:file = bufname(l:bufnr)
let l:buftype = getbufvar(l:bufnr, '&buftype')
elseif buftype == 'quickfix' if l:buftype ==# 'help'
let file = 'quickfix' let l:file = 'help:' . fnamemodify(l:file, ':t:r')
elseif buftype == 'nofile' elseif l:buftype ==# 'quickfix'
if file =~ '\/.' let l:file = 'quickfix'
let file = substitute(file, '.*\/\ze.', '', '')
elseif l:buftype ==# 'nofile'
if l:file =~# '\/.'
let l:file = substitute(l:file, '.*\/\ze.', '', '')
endif endif
else else
let file = fnamemodify(file, ':p:t') let l:file = fnamemodify(l:file, ':p:t')
endif endif
if file == '' if l:file ==# ''
let file = "''" let l:file = "''"
endif endif
let s .= file . ' %#mNoise# ' let l:customtabline .= l:file . ' %#mNoise# '
let i = i + 1 let l:tabnumber = l:tabnumber + 1
endwhile endwhile
let s .= '%T%#TabLineFill#%=' let l:customtabline .= '%T%#TabLineFill#%='
let s .= '%#mNoise# ' let l:customtabline .= '%#mNoise# '
let s .= '%#TabSeparator# "%#TabLineItemSel#%{v:register}%#TabSeparator#" ' let l:customtabline .= '%#TabSeparator# "%#TabLineItemSel#%{v:register}%#TabSeparator#" '
let s .= '%#mNoise# ' let l:customtabline .= '%#mNoise# '
let s .= "%#TabLineItemSel# %{ObsessionStatus(fnamemodify(v:this_session,':t'),'---')} %*" let l:customtabline .= "%#TabLineItemSel# %{ObsessionStatus(fnamemodify(v:this_session,':t'),'---')} %*"
return s return l:customtabline
endfunction endfunction
highlight def link TabNum Comment
highlight def link TabNumSel String
highlight def link TabSeparator Comment
highlight def link TabLineItem Comment
highlight def link TabLineItemSel String
set showtabline=2 set showtabline=2
set tabline=%!MyTabLine() set tabline=%!MyTabLine()