function! BufTabline() redir => bufsRaw silent buffers redir END let bufs = [] for buf in split(bufsRaw, "\n") let buf = substitute(buf, "\"", "", "g") let ents = [] for ent in split(buf, " ") if len(ent) == 0 | continue | endif let ents = add(ents, substitute(ent, "%", "%%", "g")) endfor let ents = ents[:-3] if len(ents) == 4 | let ents = [ents[0], ents[1] . ents[2], ents[3]] | endif if len(ents) == 3 | let ents = [ents[0] . ":" . ents[1], ents[2]] | endif let ents[0] = "%#TabLine#" . ents[0] . "%*" if len(ents[1]) > 20 | let ents[1] = "<" . ents[1][-19:] | endif if match(ents[0], "%%") == -1 let ents[1] = "%#TabLine#:" . ents[1] . "%*" else let ents[1] = "%#TabLineSel#" . ents[1] . "%*" endif let bufs = add(bufs, join(ents[:1], "")) endfor return join(bufs, "%#Comment#|%*") endfunction set showtabline=2 set tabline=%!BufTabline()