我有一个看起来像这样的调试文件:
==>func1:
.....
..
==>func2:
......
...
<==func2
..
<==func1
==>func3:
......
...
<==func3
基本上,我希望能够折叠每个功能,最终看到这样的东西:
+-- x lines: ==> func1:
+-- x lines: ==> func3:
,但仍然可以扩展func1
并查看func2
折叠:
==>func1:
.....
..
+-- x lines: ==> func2:
..
<==func1
有什么办法吗?谢谢。
无与伦比的标记需要额外的手柄,这是 expr 解决方案(请参阅:h fold-expr
):
setlocal foldmethod=expr
setlocal foldexpr=GetFoldlevel(v:lnum)
function GetFoldlevel(lnum)
let line = getline(a:lnum)
let ret = '='
if line[0:2] == '==>'
let name = matchstr(line, '^==>zsw*')
let has_match = HasMarkerMatch(a:lnum, name)
if has_match
let ret = 'a1'
endif
elseif line[0:2] == '<=='
let ret ='s1'
endif
return ret
endfunction
function HasMarkerMatch(lnum, name)
let endline = line('$')
let current = a:lnum + 1
let has_match = 0
while current <= endline
let line = getline(current)
if line =~ '^<=='.a:name
let has_match = 1
break
endif
let current += 1
endwhile
return has_match
endfunction