[英]How can I tell Vim to close only a specific level of folds in a file?
For example, how can I tell Vim to only close all level 2 folds in a file, leaving other levels open? 例如,如何告诉Vim仅关闭文件中的所有2级折叠,而使其他级保持打开状态?
Edit: Let's say I have 3 levels of folds in my file. 编辑:假设我的文件中有3个折叠级别。 1, 2, and 3. I only want to close level 2 folds, leaving levels 1 and 3 open. 1、2和3。我只想关闭2折,而1和3则保持打开状态。
You can also set 'foldlevel'
via the [count]
on zM
: 2zM
; 您还可以通过zM
上的[count]
设置'foldlevel'
: 2zM
; this is shorter than @timrau's answer. 这比@timrau的答案短。
使用foldlevel
。
:set foldlevel=2
function! FoldToTheLevel(TheLevel)
"set mark "f" at current position
execute "normal! mf"
"close all the folder recursively
execute "normal! ggVGzC"
"open all the folder which have smaller level
let h=0
while h<a:TheLevel
execute "normal! ggVGzo"
let h+=1
endwhile
"open all the folder which have larger level
folddoclosed execute "normal! VzOzc"
"jump back and show in the middle
execute "normal! `fzz"
endfunction
command! -nargs=1 F call FoldToTheLevel(<f-args>)
add this to .vimrc 将此添加到.vimrc
run 跑
:F num :F num
to close the folder which the level is {num} 关闭级别为{num}的文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.