nvim/init.fold-text.vim

53 lines
1.9 KiB
VimL
Raw Normal View History

function! MyFoldText()
if !exists('g:foldtext_column')
let g:foldtext_column = 80 " column to right align foldtext with
endif
if !exists('b:foldtext_column')
let b:foldtext_column = g:foldtext_column " column to right align foldtext with
endif
if !exists('g:foldtext_maxcolumn')
let g:foldtext_maxcolumn = 120
endif
let l:linecount = v:foldend - v:foldstart
" don't display foldmarker braces
" put one of the braces in brackets so vim doesn't treat
" it as an actual fold marker
let l:line = substitute(getline(v:foldstart), '"\?{\({\){', '', '')
" don't display vim comment quotation marks
" TODO other comment markers
let l:line = substitute(l:line, "\^\"\\s\\?", '', '')
2020-07-31 12:41:57 +00:00
" TODO replace spaces with tabs if appropriate
" replace tabs with spaces if expandtab
if &expandtab == 0
let l:tabwidth = &tabstop
let l:tabspace = ' '[1:l:tabwidth]
let l:line = substitute(l:line, ' ', l:tabspace, 'g')
endif
" let l:postfix = l:linecount . ' ' . substitute(v:folddashes, '-', '•', 'g')
let l:postfix = l:linecount . ' ' . substitute(v:folddashes, '-', '↓', 'g')
while strchars(l:postfix) < 7
let l:postfix = ' ' . l:postfix
endwhile
" let l:postfix = ' ↓ ' . l:postfix
let l:len_line = len(l:line)
let l:len_postfix = strchars(l:postfix)
if l:len_line + l:len_postfix <= b:foldtext_column
let l:padding = ' '[l:len_line + l:len_postfix + 0:b:foldtext_column - 1]
let l:foldtext = l:line . l:padding . l:postfix
else
let l:sniptext = ' ⋯'
let l:foldtext = l:line[:b:foldtext_column - 1 - strchars(l:sniptext) - l:len_postfix] . l:sniptext . l:postfix
endif
return l:foldtext
endfunction
set foldtext=MyFoldText()