Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the way that vim display those collapsed/folded lines [duplicate]

to make vim-collapse/fold more pretty

How to change the way that vim display those collapsed/folded lines(show hidden line numbers at line tail but not head). I have googled and sited vim wiki, but found no hints.

please see the picture [more pretty vim fold format]

enter image description here

the fold style is just like the right hand side of the pic.

like image 721
pambda Avatar asked Oct 22 '15 12:10

pambda


1 Answers

You can set your function to set the fold text

Try something like this:

function! MyFoldText()
    let nblines = v:foldend - v:foldstart + 1
    let w = winwidth(0) - &foldcolumn - (&number ? 8 : 0)
    let line = getline(v:foldstart)
    let comment = substitute(line, '/\*\|\*/\|{{{\d\=', '', 'g')
    let expansionString = repeat(".", w - strwidth(nblines.comment.'"'))
    let txt = '"' . comment . expansionString . nblines
    return txt
endfunction
set foldtext=MyFoldText()

v:foldend line number of last line in the fold

v:foldstart line number of first line in the fold

nblines is computed doing the diff and add 1

Then the comment is extracted removing the marker, should be improved using comment sign of the syntax and folding marker selected.

The expansionString is computed based on the winwidth

You can find the documentation here: http://vimdoc.sourceforge.net/htmldoc/fold.html#fold-foldtext

like image 101
Ôrel Avatar answered Sep 22 '22 17:09

Ôrel