-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipline.vim
227 lines (202 loc) · 7.02 KB
/
zipline.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
" Filename: zipline.vim
" Author: mikewadsten
" License: MIT License
" zipline: My own statusline implementation
" Inspiration drawn from itchyny/lightline.vim
" Most colors ripped from lightline solarized_dark scheme.
hi Zipline_Blue ctermfg=230 ctermbg=33 guifg=#ffffd7 guibg=#0087ff
hi Zipline_Red ctermfg=230 ctermbg=124 guifg=#ffffd7 guibg=#ff0000
hi Zipline_Green ctermfg=230 ctermbg=64 guifg=#ffffd7 guibg=#5f8700
hi Zipline_Magenta ctermfg=230 ctermbg=125 guifg=#ffffd7 guibg=#af005f
hi Zipline_Orange ctermfg=230 ctermbg=166 guifg=#ffffd7 guibg=#d75f00
hi Zipline_Git ctermfg=230 ctermbg=239 guifg=#ffffd7 guibg=#4b4b4b
hi Zipline_Gray ctermfg=233 ctermbg=244 guifg=#141414 guibg=#808080
hi Zipline_Grayer ctermfg=247 ctermbg=239 guifg=#111111 guibg=#999999
" Give mode highlight groups unique names
hi link Zipline_Mode_Normal Zipline_Blue
hi link Zipline_Mode_Insert Zipline_Green
hi link Zipline_Mode_Visual Zipline_Magenta
hi link Zipline_Mode_Replace Zipline_Red
hi clear StatusLine
hi StatusLine term=NONE cterm=NONE ctermfg=245 ctermbg=235 guifg=#8a8a8a guibg=#262626
hi StatusLineNC term=NONE cterm=NONE ctermfg=10 ctermbg=235 guifg=Gray guibg=#262626
hi ZiplineNC_Filename term=NONE cterm=NONE ctermfg=4 ctermbg=235 guifg=#5555ff guibg=#262626
hi Zipline_StlOrangeText ctermfg=166 ctermbg=235 guifg=#d75f00 guibg=#262626
function! zipline#mode() abort
if s:ishelp()
return '' " Addressed in zipline#helpmode()
endif
let modemap = {
\ 'n': 'normal', 'i': 'insert', 'R': 'replace', 'v': 'visual',
\ 'V': 'V-line', "\<C-v>": 'V-block', 'c': 'command',
\ 's': 'select', 'S': 's-line', "\<C-s>": 's-block',
\ 't': 'terminal' }
let l:mode = mode()
" Override for unit testing...
if exists('b:zipline_utest')
let l:mode = get(b:zipline_utest, 'mode', 'n')
endif
return ' ' . toupper(get(modemap, l:mode, printf("MODE? %s", l:mode))) . ' '
endfunction
function! s:ishelp()
return &filetype == "help"
endfunction
function! zipline#helpmode() abort
if s:ishelp()
return ' HELP '
else
return ''
endif
endfunction
function! zipline#buffers() abort
if s:ishelp()
return expand('%:t')
endif
call bufferline#refresh_status()
" bufferline#get_status_string() gets the content that we'd put in
" &statusline. We're computing that here now, though, so...
let l:before = g:bufferline_status_info.before
let l:current = g:bufferline_status_info.current
let l:after = g:bufferline_status_info.after
return l:before . l:current . l:after
endfunction
function! zipline#inactive_dir() abort
if s:ishelp()
return ''
else
return expand('%:p:~:.:h') . '/'
endif
endfunction
function! zipline#fileinfo() abort
let _ = (&filetype !=# "" ? &filetype : 'no ft')
if &fileformat != 'unix'
let _ = printf('%s | %s', &fileformat, _)
endif
return _
endfunction
function! zipline#git() abort
if exists('b:zipline_utest')
let head = get(b:zipline_utest, 'fugitive_head', '')
elseif !exists('g:loaded_fugitive')
return ''
elseif exists('*FugitiveHead')
let head = FugitiveHead()
else
let head = fugitive#head()
endif
if head == ''
" Just return empty if there's no head
return ''
endif
if strlen(head) > 18
" Avoid too-long heads
let head = printf('%.18s...', head)
endif
" Vim strips one leading space from value, because %{} is treated
" as a 'flag' (src/buffer.c:4141). Work around that by having 2 spaces.
return printf(' %s ', head)
endfunction
let s:hgroup_activemode = 'Zipline_activemode'
let s:hgroup_activebuf = 'Zipline_activebuffers'
let s:zipline = {
\ 'active': {
\ 'left': ['helpmode', 'mode', 'git', 'spacer1', 'buffers'],
\ 'right': ['fileinfo', 'spacer1', 'percent', 'lineinfo']
\ },
\ 'inactive': {
\ 'left': ['dimfile'], 'right': ['dimright']
\ },
\ 'exprs': {
\ 'mode': 'zipline#mode()',
\ 'helpmode': 'zipline#helpmode()',
\ 'git': 'zipline#git()',
\ 'buffers': 'zipline#buffers()',
\ 'fileinfo': 'zipline#fileinfo()',
\ },
\ 'formats': {
\ 'percent': ' %3p%% ',
\ 'lineinfo': ' %3l:%-2v ',
\ 'dimfile': '######## %{zipline#inactive_dir()}%0*%#ZiplineNC_Filename#%t',
\ 'dimright': '########',
\ 'spacer1': ' ',
\ },
\ 'mode_colors': {
\ 'n': 'Zipline_Mode_Normal',
\ 'i': 'Zipline_Mode_Insert',
\ 'v': 'Zipline_Mode_Visual',
\ 'V': 'Zipline_Mode_Visual',
\ "\<C-v>": 'Zipline_Mode_Visual',
\ 's': 'Zipline_Mode_Visual',
\ 'S': 'Zipline_Mode_Visual',
\ "\<C-s>": 'Zipline_Mode_Visual',
\ 'R': 'Zipline_Mode_Replace',
\ 't': 'Zipline_Mode_Insert'
\ },
\ 'highlight': {
\ 'helpmode': 'Zipline_Orange',
\ 'git': 'Zipline_Git',
\ 'buffers': s:hgroup_activebuf,
\ 'percent': 'Zipline_Grayer',
\ 'lineinfo': 'Zipline_Gray',
\ 'dimfile': 'StatusLineNC',
\ 'dimright': 'StatusLineNC'
\ },
\ }
let s:save_mode = ''
let s:save_ft = ''
let g:zipline = s:zipline
execute 'hi link ' . s:hgroup_activemode . ' Zipline_Mode_Normal'
execute 'hi link ' . s:hgroup_activebuf . ' StatusLine'
function! zipline#highlight() abort
" Relink s:hgroup_activemode according to new mode
if s:save_mode != mode() || s:save_ft != &ft
let s:save_mode = mode()
let s:save_ft = &ft
if exists('b:zipline_utest')
let curmode = get(b:zipline_utest, 'mode', 'n')
else
let curmode = mode()
endif
let hgroup = get(s:zipline.mode_colors, curmode, 'Zipline_Mode_Normal')
execute printf('hi link %s %s', s:hgroup_activemode, hgroup)
let hgroup = s:ishelp() ? "Zipline_StlOrangeText" : "StatusLine"
execute printf('hi link %s %s', s:hgroup_activebuf, hgroup)
endif
return ''
endfunction
function! s:make_pieces(pieces, sep) abort
let l:bits = []
for piece in a:pieces
if piece == 'mode'
let hgroup = s:hgroup_activemode
else
let hgroup = get(s:zipline.highlight, piece, 'StatusLine')
endif
if has_key(s:zipline.exprs, piece)
let expr = '%{' . s:zipline.exprs[piece] . '}'
elseif has_key(s:zipline.formats, piece)
let expr = s:zipline.formats[piece]
else
let expr = ''
endif
call add(l:bits, '%#' . hgroup . '#' . expr . '%0*')
endfor
return join(l:bits, a:sep)
endfunction
function! s:build_line(active)
let l:_ = '%{zipline#highlight()}'
let l:side = a:active ? s:zipline.active : s:zipline.inactive
let l:_ .= s:make_pieces(l:side.left, '') . '%=' . s:make_pieces(l:side.right, '')
return l:_
endfunction
function! zipline#update()
let curwin = winnr()
let lines = winnr('$') == 1 ? [s:build_line(1)] : [s:build_line(1), s:build_line(0)]
for w in range(1, winnr('$'))
call setwinvar(w, '&statusline', lines[w == curwin ? 0 : 1])
endfor
endfunction
augroup zipline
autocmd!
autocmd WinEnter,BufWinEnter,FileType,ColorScheme,SessionLoadPost * call zipline#update()
augroup END