diff --git a/vimrc.d/tabline.vim b/vimrc.d/tabline.vim index 1b442f0..529da63 100644 --- a/vimrc.d/tabline.vim +++ b/vimrc.d/tabline.vim @@ -1,70 +1,68 @@ -if exists("+showtabline") +if exists('+showtabline') " Rename tabs to show tab number. " based on: " http://stackoverflow.com/questions/5927952/whats-implementation-of-vims-default-tabline-function function! MyTabLine() - let s = '' - let t = tabpagenr() - let i = 1 - while i <= tabpagenr('$') - let buflist = tabpagebuflist(i) - let winnr = tabpagewinnr(i) - let s .= '%' . i . 'T' - let s .= (i == t ? '%1*' : '%2*') + 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) - let s .= (i == t ? '%#TabNumSel#' : '%#TabNum#') - let s .= ' ' . i - let s .= '%#TabSeparator#:' - let s .= (i == t ? '%#TabLineItemSel#' : '%#TabLineItem#') + if l:lasttabnumber > 1 + let l:customtabline .= '%' . l:tabnumber . 'T' + let l:customtabline .= (l:tabnumber == l:currenttabnum ? '%1*' : '%2*') - let bufnr = buflist[winnr - 1] - let file = bufname(bufnr) - let buftype = getbufvar(bufnr, '&buftype') + let l:customtabline .= (l:tabnumber == l:currenttabnum ? '%#TabNumSel#' : '%#TabNum#') + let l:customtabline .= ' ' . l:tabnumber + let l:customtabline .= '%#TabSeparator#:' + let l:customtabline .= (l:tabnumber == l:currenttabnum ? '%#TabLineItemSel#' : '%#TabLineItem#') + endif - if buftype == 'help' - let file = 'help:' . fnamemodify(file, ':t:r') + let l:bufnr = l:buflist[l:winnr - 1] + let l:file = bufname(l:bufnr) + let l:buftype = getbufvar(l:bufnr, '&buftype') - elseif buftype == 'quickfix' - let file = 'quickfix' + if l:buftype ==# 'help' + let l:file = 'help:' . fnamemodify(l:file, ':t:r') - elseif buftype == 'nofile' - if file =~ '\/.' - let file = substitute(file, '.*\/\ze.', '', '') + 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 file = fnamemodify(file, ':p:t') + let l:file = fnamemodify(l:file, ':p:t') endif - if file == '' - let file = "''" + if l:file ==# '' + let l:file = "''" endif - let s .= file . ' %#mNoise# ' + let l:customtabline .= l:file . ' %#mNoise# ' - let i = i + 1 + let l:tabnumber = l:tabnumber + 1 endwhile - let s .= '%T%#TabLineFill#%=' - let s .= '%#mNoise# ' - let s .= '%#TabSeparator# "%#TabLineItemSel#%{v:register}%#TabSeparator#" ' - let s .= '%#mNoise# ' - let s .= "%#TabLineItemSel# %{ObsessionStatus(fnamemodify(v:this_session,':t'),'---')} %*" + let l:customtabline .= '%T%#TabLineFill#%=' + let l:customtabline .= '%#mNoise# ' + let l:customtabline .= '%#TabSeparator# "%#TabLineItemSel#%{v:register}%#TabSeparator#" ' + let l:customtabline .= '%#mNoise# ' + let l:customtabline .= "%#TabLineItemSel# %{ObsessionStatus(fnamemodify(v:this_session,':t'),'---')} %*" - return s + return l:customtabline 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 tabline=%!MyTabLine()