vim/vimrc.d/tabline.vim

72 lines
1.7 KiB
VimL
Raw Normal View History

2018-04-17 17:18:15 +00:00
if exists("+showtabline")
2018-04-17 19:44:45 +00:00
" Rename tabs to show tab number.
" based on:
" http://stackoverflow.com/questions/5927952/whats-implementation-of-vims-default-tabline-function
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
function! MyTabLine()
2018-04-17 17:18:15 +00:00
let s = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
2018-04-17 19:44:45 +00:00
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let s .= '%' . i . 'T'
let s .= (i == t ? '%1*' : '%2*')
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
let s .= (i == t ? '%#TabNumSel#' : '%#TabNum#')
let s .= ' ' . i
let s .= '%#TabSeparator#:'
let s .= (i == t ? '%#TabLineItemSel#' : '%#TabLineItem#')
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
let bufnr = buflist[winnr - 1]
let file = bufname(bufnr)
let buftype = getbufvar(bufnr, '&buftype')
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
if buftype == 'help'
let file = 'help:' . fnamemodify(file, ':t:r')
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
elseif buftype == 'quickfix'
let file = 'quickfix'
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
elseif buftype == 'nofile'
if file =~ '\/.'
let file = substitute(file, '.*\/\ze.', '', '')
endif
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
else
2018-04-17 20:56:24 +00:00
let file = fnamemodify(file, ':p:t')
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
endif
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
if file == ''
let file = "''"
endif
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
let s .= file . ' %#mNoise# '
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
let i = i + 1
2018-04-17 17:18:15 +00:00
endwhile
let s .= '%T%#TabLineFill#%='
2018-04-17 19:34:14 +00:00
let s .= '%#mNoise# '
let s .= '%#TabSeparator# "%#TabLineItemSel#%{v:register}%#TabSeparator#" '
let s .= '%#mNoise# '
let s .= "%#TabLineItemSel# %{ObsessionStatus(fnamemodify(v:this_session,':t'),'---')} %*"
2018-04-17 17:18:15 +00:00
return s
2018-04-17 19:44:45 +00:00
endfunction
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
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
2018-04-17 17:18:15 +00:00
2018-04-17 19:44:45 +00:00
set showtabline=2
set tabline=%!MyTabLine()
2018-04-17 17:18:15 +00:00
endif " exists("+showtabline")