Skip to content

Instantly share code, notes, and snippets.

@grauwoelfchen
Created October 25, 2013 16:37
Show Gist options
  • Save grauwoelfchen/7157667 to your computer and use it in GitHub Desktop.
Save grauwoelfchen/7157667 to your computer and use it in GitHub Desktop.
tabline with buffers and hostname
function! s:tab_label(n)
let bufnrs = tabpagebuflist(a:n)
let curbufnr = bufnrs[tabpagewinnr(a:n) - 1]
let hl = a:n ==? tabpagenr() ? 'TabLineSel' : 'TabLine'
let bufs = len(bufnrs)
if bufs == 1
let bufs = ''
else
let bufs = '%#'.hl.'Number#'.bufs
end
let updated = len(filter(copy(bufnrs), 'getbufvar(v:val, "&modified")')) ? '+' : ''
let blank = (bufs.updated) ==? '' ? '' : ' '
let fname = pathshorten(bufname(curbufnr))
return '%'.a:n.'T'.bufs.updated.blank.'%#'.hl.'#'.fname.'%T%#TablineFill#'
endfunction
function! MakeTabLine()
let labels = map(range(1, tabpagenr('$')), 's:tab_label(v:val)')
let separator = " | "
let tabs = ' ' . join(labels, separator).separator."%#TablineFill#%T"
let info = fnamemodify(getcwd(), ':~').' « '.hostname().' » '
return tabs.'%='.info
endfunction
set showtabline=2
set tabline=%!MakeTabLine()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment