例如,我怎么能告诉Vim只关闭文件中的所有2级折叠,让其他级别打开?
编辑:假设我的文件中有3个级别的折叠。 1,2和3.我只想关闭2级,将1级和3级打开。
答案 0 :(得分:3)
您还可以通过'foldlevel'
上的[count]
设置zM
:2zM
;这比@ timrau的答案要短。
答案 1 :(得分:2)
使用foldlevel
。
:set foldlevel=2
答案 2 :(得分:1)
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>)
将此添加到.vimrc
运行
:F num
关闭级别为{num}
的文件夹