forked from rafi/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnicefold.vim
More file actions
55 lines (49 loc) · 1.54 KB
/
nicefold.vim
File metadata and controls
55 lines (49 loc) · 1.54 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
" Nice Fold
" ---
"
" Behaviors:
" - Improve folds performance after modification
" - Set a nice pattern for collapsed folds
if exists('g:loaded_nicefold')
finish
endif
let g:loaded_nicefold = 1
" Fast fold
" Credits: https://github.com/Shougo/shougo-s-github
augroup plugin_fastfold
autocmd!
autocmd TextChangedI,TextChanged *
\ if &l:foldenable && &l:foldmethod !=# 'manual'
\| let b:foldmethod_save = &l:foldmethod
\| let &l:foldmethod = 'manual'
\| endif
autocmd BufWritePost *
\ if &l:foldmethod ==# 'manual' && exists('b:foldmethod_save')
\| let &l:foldmethod = b:foldmethod_save
\| execute 'normal! zx'
\| endif
augroup END
if has('folding')
set foldtext=FoldText()
endif
" Improved Vim fold-text
" See: http://www.gregsexton.org/2011/03/improving-the-text-displayed-in-a-fold/
function! FoldText()
" Get first non-blank line
let fs = v:foldstart
while getline(fs) =~? '^\s*$' | let fs = nextnonblank(fs + 1)
endwhile
if fs > v:foldend
let line = getline(v:foldstart)
else
let line = substitute(getline(fs), '\t', repeat(' ', &tabstop), 'g')
endif
let w = winwidth(0) - &foldcolumn - (&number ? 8 : 0)
let foldSize = 1 + v:foldend - v:foldstart
let foldSizeStr = ' ' . foldSize . ' lines '
let foldLevelStr = repeat('+--', v:foldlevel)
let lineCount = line('$')
let foldPercentage = printf('[%.1f', (foldSize*1.0)/lineCount*100) . '%] '
let expansionString = repeat('.', w - strwidth(foldSizeStr.line.foldLevelStr.foldPercentage))
return line . expansionString . foldSizeStr . foldPercentage . foldLevelStr
endfunction