Vim折叠:如何隐藏所有不包含搜索模式的单行(或折叠零线)?

ThG*_*ThG 2 vim folding

我有文本文件,只是没有段落的列表.当我想专注于一个项目时,我能够将除了匹配之外的所有内容折叠到我的搜索中,这要归功于Vim Wikia(提示282:"简单折叠"):

:set foldexpr=getline(v:lnum)!~@/
:nnoremap <F8> :set foldmethod=expr<CR><Bar>zM
Run Code Online (Sandbox Code Playgroud)

这被证明是有用的:因此我可以非常清楚地看到我正在寻找的物品:它们在黑色背景上呈现白色,而褶皱是灰色(ctermbg)上的暗灰色(ctermfg).

但是有一个 - 次要 - 故障.可能发生(并且实际上经常发生)不包含图案的单条线保留在包含图案的两条线之间,例如:

1 pattern
2 not pattern
3 not pattern
4 pattern
5 not pattern
6 pattern
Run Code Online (Sandbox Code Playgroud)

简单的折叠将折叠第2和第3行,而不是第5行.

我应该如何隐藏这条单线呢?

有没有办法折叠零线(这让我想起了一只手鼓掌的公案......)?我想这是不可能的.

那么,有没有办法简单地用一个函数隐藏线条(例如与折叠相同的突出显示)?

Ken*_*ent 6

尝试set另一种选择:

set fml=0
Run Code Online (Sandbox Code Playgroud)

有关此选项的详细信息:

:h 'fml' 
Run Code Online (Sandbox Code Playgroud)

与您的问题相关:

 With the default value of
    one a fold can only be closed if it takes up two or more screen lines.
    Set to zero to be able to close folds of just one screen line.
Run Code Online (Sandbox Code Playgroud)