This repository was archived by the owner on Apr 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtinyline.vim
More file actions
259 lines (223 loc) · 7.97 KB
/
tinyline.vim
File metadata and controls
259 lines (223 loc) · 7.97 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
" vim-tinyline - Tiny status line for Vim
" Maintainer: Rafael Bodill <justrafi at gmail dot com>
" Version: 0.8
"-------------------------------------------------
" Disable reload {{{
if exists('g:loaded_tinyline') && g:loaded_tinyline
finish
endif
let g:loaded_tinyline = 1
" }}}
" Saving 'cpoptions' {{{
let s:save_cpo = &cpo
set cpo&vim
" }}}
" Configuration {{{
" Maximum number of directories in filepath
if ! exists('g:tinyline_max_dirs')
let g:tinyline_max_dirs = 3
endif
" Maximum number of characters in each directory
if ! exists('g:tinyline_max_dir_chars')
let g:tinyline_max_dir_chars = 5
endif
" Less verbosity on specific filetypes (regexp)
if ! exists('g:tinyline_quiet_filetypes')
let g:tinyline_quiet_filetypes = 'qf\|help\|unite\|vimfiler\|gundo\|diff\|fugitive\|gitv'
endif
" }}}
" Command {{{
command! -nargs=0 -bar -bang TinyLine call s:tinyline('<bang>' == '!')
" }}}
" 3rd-Party Plugin Detection {{{
let s:has_branchname = exists('*gitbranch#name') ||
\ (exists('*dein#get') && ! empty(dein#get('vim-gitbranch')))
let s:has_fugitive = exists('*fugitive#head') ||
\ (exists('*dein#get') && ! empty(dein#get('vim-fugitive')))
let s:has_vcs = exists('*vcs#info') ||
\ (exists('*dein#get') && ! empty(dein#get('vim-vcs')))
" }}}
function! s:tinyline(disable) " {{{
" Toggles TinyLine
if a:disable
set statusline=
augroup TinyLine
autocmd!
augroup END
augroup! TinyLine
else
let &l:statusline = s:stl
call tinyline#define_highlights()
augroup TinyLine
autocmd!
" On save, clear cached filename, syntax, and whitespace info
autocmd BufWritePost *
\ unlet! b:tinyline_whitespace b:tinyline_syntax b:tinyline_filepath
" Toggle buffer's inactive/active statusline
autocmd WinEnter,FileType,BufWinEnter * let &l:statusline = s:stl
autocmd ColorScheme * call tinyline#define_highlights()
autocmd WinLeave * let &l:statusline = s:stl_nc
" For quickfix windows
"autocmd BufReadPost * let &l:statusline = s:stl
augroup END
endif
endfunction
" }}}
function! tinyline#define_highlights() " {{{
" Set statusline colors
hi StatusLine ctermfg=236 ctermbg=248 guifg=#30302c guibg=#a8a897
hi StatusLineNC ctermfg=236 ctermbg=242 guifg=#30302c guibg=#666656
" Custom tinyline colors
" Filepath color
hi User1 guifg=#D7D7BC guibg=#30302c ctermfg=251 ctermbg=236
" Line and column information
hi User2 guifg=#a8a897 guibg=#4e4e43 ctermfg=248 ctermbg=239
" Line and column corner arrow
hi User3 guifg=#4e4e43 guibg=#30302c ctermfg=239 ctermbg=236
" Buffer # symbol and whitespace or syntax errors
hi User4 guifg=#666656 guibg=#30302c ctermfg=242 ctermbg=236
" Write symbol
hi User6 guifg=#cf6a4c guibg=#30302c ctermfg=167 ctermbg=236
" Paste symbol
hi User7 guifg=#99ad6a guibg=#30302c ctermfg=107 ctermbg=236
" Syntax and whitespace
hi User8 guifg=#ffb964 guibg=#30302c ctermfg=215 ctermbg=236
endfunction
" }}}
function! TlSuperName() " {{{
" Provides relative path with limited characters in each directory name, and
" limits number of total directories. Caches the result for current buffer.
" Use buffer's cached filepath
if exists('b:tinyline_filepath') && len(b:tinyline_filepath) > 0
return b:tinyline_filepath
endif
" VimFiler status string
if &ft ==# 'vimfiler'
let b:tinyline_filepath = vimfiler#get_status_string()
" Empty if owned by certain plugins
elseif &ft =~? g:tinyline_quiet_filetypes
let b:tinyline_filepath = ''
" Placeholder for empty buffer
elseif expand('%:t') ==? ''
let b:tinyline_filepath = 'N/A'
" Regular file
else
" Shorten dir names
let short = substitute(expand('%'), "[^/]\\{".g:tinyline_max_dir_chars."}\\zs[^/]\*\\ze/", '', 'g')
" Decrease dir count
let parts = split(short, '/')
if len(parts) > g:tinyline_max_dirs
let parts = parts[-g:tinyline_max_dirs-1 : ]
endif
let b:tinyline_filepath = join(parts, '/')
endif
if exists('b:fugitive_type') && b:fugitive_type ==# 'blob'
let b:tinyline_filepath .= ' (blob)'
endif
return b:tinyline_filepath
endfunction
" }}}
function! TlBranchName() " {{{
" Returns git branch name, using plugins: Shougo/vim-vcs or Fugitive
if &ft !~? g:tinyline_quiet_filetypes
if s:has_branchname
return gitbranch#name()
elseif s:has_vcs
return vcs#info('%b')
elseif s:has_fugitive
return fugitive#head(8)
endif
endif
return ''
endfunction
" }}}
function! TlMode() " {{{
" Returns file's mode: read-only and/or zoomed
let s:modes = ''
if &ft !~? g:tinyline_quiet_filetypes && &readonly
let s:modes .= ''
endif
if exists('t:zoomed') && bufnr('%') == t:zoomed
let s:modes .= 'Z'
endif
return s:modes
endfunction
" }}}
function! TlFormat() " {{{
" Returns file format
return &ft =~? g:tinyline_quiet_filetypes ? '' : &ff
endfunction
" }}}
function! TlModified() " {{{
" Make sure we ignore &modified when choosewin is active
let choosewin = exists('g:choosewin_active') && g:choosewin_active
return &modified && ! choosewin ? '+' : ''
endfunction
" }}}
function! TlSyntax() " {{{
if ! exists('b:tinyline_syntax') || &ft !~? g:tinyline_quiet_filetypes
let b:tinyline_syntax = ''
if exists('*neomake#Make')
let b:tinyline_syntax = neomake#statusline#LoclistStatus()
elseif exists('*SyntasticStatuslineFlag')
let b:tinyline_syntax = SyntasticStatuslineFlag()
endif
endif
return b:tinyline_syntax
endfunction
" }}}
function! TlWhitespace() " {{{
" Detect trailing whitespace and cache result per buffer
if ! exists('b:tinyline_whitespace')
let b:tinyline_whitespace = ''
if ! &readonly && &modifiable && line('$') < 9000
let trailing = search('\s$', 'nw')
if trailing != 0
let b:tinyline_whitespace .= printf('trail %s', trailing)
endif
endif
endif
return b:tinyline_whitespace
endfunction
" }}}
" Concat the active statusline {{{
" ------------------------------------------=--------------------=------------
" Gibberish | What da heck? | Example
" ------------------------------------------+--------------------+------------
set statusline= "| Clear status line |
set statusline+=\ %7*%{&paste?'=':''}%* "| Paste symbol | =
set statusline+=%4*%{&ro?'':'#'}%* "| Modifiable symbol | #
set statusline+=%6*%{TlMode()} "| Readonly symbol |
set statusline+=%*%n "| Buffer number | 3
set statusline+=%6*%{TlModified()}%0* "| Write symbol | +
set statusline+=\ %1*%{TlSuperName()}%* "| Relative supername | cor/app.js
set statusline+=\ %< "| Truncate here |
set statusline+=%(\ %{TlBranchName()}\ %) "| Git branch name | master
set statusline+=%4*%(%{TlWhitespace()}\ %) "| Space and indent | trail34
set statusline+=%(%{TlSyntax()}\ %)%* "| syntax error/warn | E:1W:1
set statusline+=%= "| Align to right |
set statusline+=%{TlFormat()}\ %4*%* "| File format | unix
set statusline+=%(\ %{&fenc}\ %) "| File encoding | utf-8
set statusline+=%4*%*%(\ %{&ft}\ %) "| File type | python
set statusline+=%3*%2*\ %l/%2c%4p%%\ %* "| Line and column | 69:77/ 90%
" ------------------------------------------'--------------------'---------}}}
" Non-active statusline {{{
" ------------------------------------------+--------------------+------------
let s:stl_nc = " %{&paste?'=':''}" "| Paste symbol | =
let s:stl_nc.= '%{TlMode()}%n' "| Readonly & buffer | 7
let s:stl_nc.= '%6*%{TlModified()}%*' "| Write symbol | +
let s:stl_nc.= ' %{TlSuperName()}' "| Relative supername | src/main.py
let s:stl_nc.= '%=' "| Align to right |
let s:stl_nc.= '%{&ft} ' "| File type | python
" ------------------------------------------'--------------------'---------}}}
" Run-time {{{
" Store the active statusline for later toggling
let s:stl = &g:statusline
" Enable plugin by default
TinyLine
" }}}
" Restore 'cpoptions' {{{
let &cpo = s:save_cpo
unlet s:save_cpo
" }}}
" vim: set ts=2 sw=2 tw=80 noet :