离开折叠时Vim自动折叠

时间:2014-07-12 08:41:11

标签: vim folding

当我离开时,我想让vim自动关闭我的折叠。意味着当我的光标处于折叠时,折叠应该显示,但是当它(假设)在光线下方5行时它应该再次关闭。

这些是我的折叠设置:

set foldenable
set foldlevel=0
set foldnestmax=1
set foldmethod=indent
set foldtext=FoldText()

function FoldText()
    return '...'
endfunction

可以找到完整的来源here

我该怎么做?据我所知,vim没有为此功能提供任何选项,因此必须有一些autocmd

博多

1 个答案:

答案 0 :(得分:4)

Vim提供了执行此操作的选项,称为'foldclose'并且行为如此,将其设置为all

有关详细信息,请参阅帮助:

'foldclose' 'fcl'   string (default "")
            global
            {not in Vi}
            {not available when compiled without the |+folding|
            feature}
    When set to "all", a fold is closed when the cursor isn't in it and
    its level is higher than 'foldlevel'.  Useful if you want folds to
    automatically close when moving out of them.