forked from PegasusWang/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabline.vim
96 lines (79 loc) · 2.49 KB
/
tabline.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
" Tabline
" ---
" Configuration
let g:badge_numeric_charset =
\ get(g:, 'badge_numeric_charset',
\ ['⁰','¹','²','³','⁴','⁵','⁶','⁷','⁸','⁹'])
"\ ['₀','₁','₂','₃','₄','₅','₆','₇','₈','₉'])
" Limit display of directories in path
let g:badge_tab_filename_max_dirs =
\ get(g:, 'badge_tab_filename_max_dirs', 1)
" Limit display of characters in each directory in path
let g:badge_tab_dir_max_chars =
\ get(g:, 'badge_tab_dir_max_chars', 5)
" Display entire tabline
function! Tabline()
if exists('g:SessionLoad')
" Skip tabline render during session loading
return ''
endif
" Active project name
let l:tabline =
\ '%#TabLineAlt# %{" " . badge#project()} %#TabLineAltShade#'
" Iterate through all tabs and collect labels
let l:current = tabpagenr()
for i in range(tabpagenr('$'))
let l:nr = i + 1
let l:bufnrlist = tabpagebuflist(l:nr)
let l:bufnr = l:bufnrlist[tabpagewinnr(l:nr) - 1]
" Left-side of single tab
if l:nr == l:current
let l:tabline .= '%#TabLineFill#%#TabLineSel# '
else
let l:tabline .= '%#TabLine# '
endif
" Get file-name with custom cutoff settings
let l:tabline .= '%' . l:nr . 'T%{badge#filename('
\ . l:bufnr . ', ' . g:badge_tab_filename_max_dirs . ', '
\ . g:badge_tab_dir_max_chars . ', "tabname")}'
" Append window count, for tabs
let l:win_count = tabpagewinnr(l:nr, '$')
for l:bufnr in l:bufnrlist
let l:bufname = bufname(l:bufnr)
if empty(l:bufname) || l:bufname =~
\ '^\(denite\|defx\|fugitive\|magit\|fern\|hover\|clap_\|Telescope\)'
let l:win_count -= 1
endif
endfor
if l:win_count > 1
let l:tabline .= s:numtr(l:win_count, g:badge_numeric_charset)
endif
" Add '+' if one of the buffers in the tab page is modified
for l:bufnr in l:bufnrlist
if getbufvar(l:bufnr, "&modified")
let l:tabline .= (l:nr == l:current ? '%#Number#' : '%6*') . '+%*'
break
endif
endfor
" Right-side of single tab
if l:nr == l:current
let l:tabline .= '%#TabLineSel# %#TabLineFill#'
else
let l:tabline .= '%#TabLine# '
endif
endfor
" Empty elastic space and session indicator
let l:tabline .=
\ '%#TabLineFill#%T%=%#TabLine#' .
\ '%{badge#session("' . fnamemodify(v:this_session, ':t:r') . ' ")}'
return l:tabline
endfunction
function! s:numtr(number, charset) abort
let l:result = ''
for l:char in split(a:number, '\zs')
let l:result .= a:charset[l:char]
endfor
return l:result
endfunction
let &tabline='%!Tabline()'
" vim: set ts=2 sw=2 tw=80 noet :