【问题标题】:Vim - add one line above the fold to the foldingVim - 在折叠上方添加一行到折叠
【发布时间】:2020-02-14 18:32:19
【问题描述】:

当我在 vim 中编码时,我使用 set foldmethod=syntax 折叠我的代码。 它看起来像这样:

如何将{ 上方的行添加到折叠中?所以它看起来像这样:

所以想法是它(总是)将折叠上方的线放入折叠中。 我怎样才能做到这一点?

【问题讨论】:

    标签: vim fold brackets


    【解决方案1】:

    这需要一个自定义的fold expression (h fold-expr) 独立来自:

    1. foldtext
    2. foldignore { 和 } 无论缩进多少

    在你的 vimrc 中:

    " Callback: Fold level <- next line indent
    function! FoldMethod(lnum)
        let l:indent = max([indent(a:lnum+1), indent(a:lnum)])
        return l:indent / &shiftwidth
    endfunction
    
    set foldmethod=expr
    set foldexpr=FoldMethod(v:lnum)
    

    【讨论】:

      猜你喜欢
      • 2011-07-01
      • 2013-01-16
      • 2013-12-07
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 2015-11-04
      • 2011-04-09
      • 1970-01-01
      相关资源
      最近更新 更多