-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathautocmds.vim
74 lines (66 loc) · 2.55 KB
/
autocmds.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
let g:WincentColorColumnBlacklist = ['diff', 'gundo', 'nerdtree', 'qf']
let g:WincentCursorlineBlacklist = ['command-t']
let g:WincentMkviewFiletypeBlacklist = ['diff', 'hgcommit', 'gitcommit']
function! autocmds#should_colorcolumn()
return index(g:WincentColorColumnBlacklist, &filetype) == -1
endfunction
function! autocmds#should_cursorline()
return index(g:WincentCursorlineBlacklist, &filetype) == -1
endfunction
" Loosely based on: http://vim.wikia.com/wiki/Make_views_automatic
function! autocmds#should_mkview()
return
\ &buftype == '' &&
\ index(g:WincentMkviewFiletypeBlacklist, &filetype) == -1
endfunction
function! autocmds#blur_statusline()
" Default blurred statusline (buffer number: filename).
let l:blurred='%#User2#' " higlight (same as MatchParens, plus italics)
let l:blurred.='%{statusline#gutterpadding(0)}'
let l:blurred.='\ ' " space
let l:blurred.='%<' " truncation point
let l:blurred.='%f' " filename
let l:blurred.='%=' " split left/right halves (makes background cover whole)
let l:blurred.='%*' " reset highlight
call s:update_statusline(l:blurred, 'blur')
endfunction
function! autocmds#focus_statusline()
" `setlocal statusline=` will revert to global 'statusline' setting.
call s:update_statusline('', 'focus')
endfunction
function! s:update_statusline(default, action)
let l:statusline = s:get_custom_statusline(a:action)
if type(l:statusline) == type('')
" Apply custom statusline.
execute 'setlocal statusline=' . l:statusline
elseif l:statusline == 0
" Do nothing.
"
" Note that order matters here because of Vimscript's insane coercion rules:
" when comparing a string to a number, the string gets coerced to 0, which
" means that all strings `== 0`. So, we must check for string-ness first,
" above.
return
else
execute 'setlocal statusline=' . a:default
endif
endfunction
function! s:get_custom_statusline(action)
if &ft == 'command-t'
" Will use Command-T-provided buffer name, but need to escape spaces.
return '\ \ ' . substitute(bufname('%'), ' ', '\\ ', 'g')
elseif &ft == 'diff' && bufname('%') == '__Gundo_Preview__'
return 'Gundo\ Preview' " Less ugly, and nothing really useful to show.
elseif &ft == 'gundo'
return 'Gundo' " Less ugly, and nothing really useful to show.
elseif &ft == 'nerdtree'
return 0 " Don't override; NERDTree does its own thing.
elseif &ft == 'qf'
if a:action == 'blur'
return 'Quickfix'
else
return g:WincentQuickfixStatusline
endif
endif
return 1 " Use default.
endfunction