Change the text in folds

后端 未结 2 1376
温柔的废话
温柔的废话 2020-12-09 13:07

I noticed that fold texts can show useful information. They usually show something like

+-- 5 lines:

--------------------------
相关标签:
2条回答
  • 2020-12-09 13:21

    You can also inspect the folding config from Steve Losh’s bitbucket repo page about vim.

    It has very beautiful appearance, which is also very organized!

    To see what it is like, you might ckeck it out in this youtuebe video.

    0 讨论(0)
  • 2020-12-09 13:37

    There are a few things I don't understand from your question, such as which foldmethod you are using, or what the number of "rows" refers to, but here's a custom foldtext function that should do roughly what you want:

    function! MyFoldText()
        let nl = v:foldend - v:foldstart + 1
        let comment = substitute(getline(v:foldstart),"^ *","",1)
        let linetext = substitute(getline(v:foldstart+1),"^ *","",1)
        let txt = '+ ' . linetext . ' : "' . comment . '" : length ' . nl
        return txt
    endfunction
    set foldtext=MyFoldText()
    

    Explanation:

    1. Find the number of lines contained by the fold.
    2. Get the "comment" from the line before the first folded line (and remove leading spaces).
    3. Get the text from the first line of the fold (and remove leading spaces).
    4. Assemble the above information into the returned foldtext, with appropriate formatting.

    Hope this helps. It should be easily tailored to your needs.

    0 讨论(0)
提交回复
热议问题