-
Notifications
You must be signed in to change notification settings - Fork 0
/
vim-statusline.vim
147 lines (125 loc) · 4.76 KB
/
vim-statusline.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
if !has('statusline')
finish
endif
" Don't show the current mode; it's already shown on the status line.
set noshowmode
function! RKStatusLineCurLine()
return '㆔' . printf('%*d', len(line('$')), line('.'))
endfunction
let s:modes = {
\ 'n': { 'text': 'N', 'modifier': 'n' },
\ 'i': { 'text': 'I', 'modifier': 'i' },
\ 'R': { 'text': 'R', 'modifier': 'r' },
\ 'v': { 'text': 'V', 'modifier': 'v' },
\ 'V': { 'text': 'VL', 'modifier': 'v' },
\ '': { 'text': 'VB', 'modifier': 'v' },
\ 's': { 'text': 'S', 'modifier': 'n' },
\ 'S': { 'text': 'SL', 'modifier': 'n' },
\ '^S': { 'text': 'SB', 'modifier': 'n' },
\ 'c': { 'text': 'C', 'modifier': 'n' },
\ }
function! RKGitBranch()
let l:head = FugitiveHead(7)
if l:head == ''
return ''
else
" TODO Include ± char when directory status is dirty.
return ' ᚠ ' . l:head
endif
endfunction
function! RKStatusLineMode(winnum)
let l:active = a:winnum == winnr()
let l:bufnum = winbufnr(a:winnum)
let l:left1 = ' %-2(' . get(s:modes, mode(), {'text':'<' . mode() . '>'}).text . '%) '
let l:left1 = l:left1 . '%{ &paste ? "(PASTE) " : "" }'
let l:left1 = l:left1 . '%{ &spell ? "(SPELL) " : "" }'
let l:left3 = '%(%{RKGitBranch()}%)'
let l:left3 = l:left3 . ' [%{ &readonly ? "○": "●" }] '
let l:right1 = ' %3p%% '
let l:right1 = l:right1 . '%{RKStatusLineCurLine()}/%L '
let l:right1 = l:right1 . '%3c‖ '
let l:right2 = ' %{&fileencoding . "/" . &fileformat} '
let l:right3 = ' %{&filetype} '
let l:main = ' %f %m%='
if l:active
let l:modifier = get(s:modes, mode(), {'modifier': 'n'}).modifier
let l:color1 = printf('StatusLine1%s', l:modifier)
let l:color2 = printf('StatusLine2%s', l:modifier)
let l:color3 = printf('StatusLine3%s', l:modifier)
let l:color1_2 = printf('StatusLine1_2%s', l:modifier)
let l:color1_3 = printf('StatusLine1_3%s', l:modifier)
let l:color1_4 = printf('StatusLine1_4%s', l:modifier)
let l:color2_3 = printf('StatusLine2_3%s', l:modifier)
let l:color3_4 = printf('StatusLine3_4%s', l:modifier)
let l:result = '%#' . l:color1 . '#' . l:left1
if len(l:left3) > 0
let l:result = l:result . '%#' . l:color1_3 . '#%#' . l:color3 . '#' . l:left3 . '%#' . l:color3_4 . '#'
else
let l:result = l:result . '%#' . l:color1_4 . '#'
endif
let l:result = l:result . '%*' . l:main . '%#' . l:color3_4 . '#%#' . l:color3 . '#' . l:right3 . '%#' . l:color2_3 . '#%#' . l:color2 . '#' . l:right2 . '%#' . l:color1_2 . '#%#' . l:color1 . '#' . l:right1 . '%*'
else
let l:result = l:left1
if len(l:left3) > 0
let l:result = l:result . l:left3
endif
let l:result = l:result . l:main . l:right3 . l:right2 . l:right1
endif
return l:result
endfunction
function! s:RefreshStatus()
for nr in range(1, winnr('$'))
call setwinvar(nr, '&statusline', '%!RKStatusLineMode(' . nr . ')')
endfor
endfunction
if has('autocmd')
augroup status
autocmd!
autocmd VimEnter,WinEnter,BufWinEnter * call <SID>RefreshStatus()
augroup END
endif
set laststatus=2 " always show status bar
function s:set_up_status_colors()
" TODO: Inactive vs. active statusline
let l:colors={
\ 'n': [{'bg': 148, 'fg': 22}, {'bg': 19, 'fg': 20}, {'bg': 236, 'fg': 247}, {'bg': 233}],
\ 'i': [{'bg': 231, 'fg': 23}, {'bg': 31, 'fg': 74}, {'bg': 24, 'fg': 117}],
\ 'r': [{'bg': 160, 'fg': 231}],
\ 'v': [{'bg': 214, 'fg': 232}],
\ }
let l:cmd = printf(':highlight StatusLine ctermfg=231 ctermbg=%d', l:colors['n'][3].bg)
exec l:cmd
let l:cmd = printf(':highlight StatusLineNC ctermfg=247 ctermbg=%d', l:colors['n'][3].bg)
exec l:cmd
for M in ['n', 'i', 'r', 'v']
" First mode style
let l:label = printf('StatusLine1x%s', M)
let l:cmd = printf(':highlight %s ctermfg=%d ctermbg=%d cterm=bold', l:label, l:colors[M][0].fg, l:colors[M][0].bg)
exec l:cmd
" Mode styles per level
for L in [1, 2, 3]
let l:label = printf('StatusLine%d%s', L, M)
if L - 1 < len(l:colors[M])
let l:cmd = printf(':highlight %s ctermfg=%d ctermbg=%d', l:label, l:colors[M][L-1].fg, l:colors[M][L-1].bg)
else
let l:firstlabel = printf('StatusLine%d%s', L, 'n')
let l:cmd = printf(':highlight link %s %s', l:label, l:firstlabel)
endif
exec l:cmd
endfor
" Mode style level transitions
for L1 in [1, 2, 3]
let L2 = L1+1
while L2 <= 4
let l:label = printf('StatusLine%d_%d%s', L1, L2, M)
let l:bg1 = get(l:colors[M], L1-1, l:colors['n'][L1-1]).bg
let l:bg2 = get(l:colors[M], L2-1, l:colors['n'][L2-1]).bg
let l:cmd = printf(':highlight %s ctermfg=%d ctermbg=%d', l:label, l:bg1, l:bg2)
exec l:cmd
let L2 = L2+1
endwhile
endfor
endfor
endfunction
call s:set_up_status_colors()
" vim: set sw=2 et: