更新

更新

在 vim 中我想改变折叠行为。假设我折叠这个块:

=== fileName ===

        == summary ==

                I think that this defines the class to use for the authentication
                and the parameters to pass the class.

        == tags ==

                <bla bla>
                </bla bla>

它成为了:

=== fileName ===

        == summary ==

+---  2 lines: I think that this defines the class to use for the authentication------------

        == tags ==

                <bla bla>
                </bla bla>

我认为如果变成这样会更容易阅读:

=== fileName ===

        == summary ==

                +---  2 lines: I think that this defines the class to use for the authentication------------

        == tags ==

                <bla bla>
                </bla bla>

(所需结果有一个额外的标签)

仅供参考:我的 vimrc 中有这个:

"use indents as the folding method
set foldmethod=indent

"make vim save and load the folding of the document each time it loads
au BufWinLeave * mkview
au BufWinEnter * silent loadview

更新

根据推荐新泽西我尝试将 foldtext 设置为我自己的函数。我尝试了他建议的那个和下面的那个。然而都没有任何效果。

function! MyFoldText()
  return 'johnny'
endfunction

set foldtext=MyFoldText()

我在这里遗漏了什么?

笔记:set foldmethod=indent我的 .vimrc 中 也有这个:

答案1

所以您想让折叠消息与折叠文本的缩进对齐吗?

您需要将“ foldtext”选项设置为非默认选项折叠文本()功能。

像这样:

function! MyFoldText()
  let lines = 1 + v:foldend - v:foldstart
  let spaces = repeat(' ', indent(v:foldstart))

  let linestxt = 'lines'
  if lines == 1
    linestxt = 'line'
  endif

  let firstline = getline(v:foldstart)
  let line = firstline[ind : ind+80]

  return spaces . '+' . v:folddashes . ' ' . lines . ' ' . linestxt . ': ' . line . ' '
endfunction

然后

:set foldtext=MyFoldText()

相关内容