【问题标题】:Is there any way to adjust the format of folded lines in vim?有什么办法可以调整vim中折叠线的格式吗?
【发布时间】:2012-09-29 11:05:35
【问题描述】:

现在我的折叠线看起来像这样:

+-- 123 lines: doSomeStuff();--------------------------
+-- 345 lines: doSomeOtherStuff();---------------------

我想删除一行实际内容之前的所有内容(+-- xxx 行:),使其更像 Notepad++/Eclipse 视觉方式 - 现在它太难阅读了,我实际上不在乎如何我在某个折叠下有很多行:) 那么有什么命令可以调整折叠线的格式吗?

【问题讨论】:

    标签: vim folding


    【解决方案1】:

    是的,foldtext romainl 已经提到的函数返回一个要在闭合折叠中显示的字符串(换句话说,就是你所看到的)。

    您可以修改折叠功能以显示您感兴趣的任何内容。例如,

    function! MyFoldText() " {{{
        let line = getline(v:foldstart)
    
        let nucolwidth = &fdc + &number * &numberwidth
        let windowwidth = winwidth(0) - nucolwidth - 3
        let foldedlinecount = v:foldend - v:foldstart
    
        " expand tabs into spaces
        let onetab = strpart('          ', 0, &tabstop)
        let line = substitute(line, '\t', onetab, 'g')
    
        let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
        let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
        return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
    endfunction " }}}
    set foldtext=MyFoldText()
    

    会返回类似的东西

    " Basic settings --------------------------------------------- {{{...              6 ...
    

    表示6行在折叠中(包括带有关闭折叠标记的那一行)

    【讨论】:

      【解决方案2】:

      :help fold-foldtext 拥有您需要的所有信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-06
        • 2022-11-25
        • 1970-01-01
        相关资源
        最近更新 更多