如何告诉Vim仅关闭文件中特定级别的折叠?
例如,我如何告诉Vim只关闭文件中的所有级别2折叠,而不关闭其他级别 编辑:假设我的文件中有3层折叠。一,二,三。我只想关闭2层折叠,让1层和3层打开。使用 使用如何告诉Vim仅关闭文件中特定级别的折叠?,vim,Vim,例如,我如何告诉Vim只关闭文件中的所有级别2折叠,而不关闭其他级别 编辑:假设我的文件中有3层折叠。一,二,三。我只想关闭2层折叠,让1层和3层打开。使用 使用 您还可以通过zM上的[count]设置'foldlevel':2zM;这比@timrau的答案要短。您也可以通过zM上的[count]设置'foldlevel';这比@timrau的答案要短。函数!折叠到标高(标高) function! FoldToTheLevel(TheLevel) "set mark "f" at
您还可以通过
zM
上的[count]
设置'foldlevel'
:2zM
;这比@timrau的答案要短。您也可以通过zM
上的[count]
设置'foldlevel'
;这比@timrau的答案要短。函数!折叠到标高(标高)
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>)
“在当前位置设置标记“f”
执行“正常!mf“
“递归关闭所有文件夹
执行“normal!ggVGzC”
“打开所有级别较小的文件夹
设h=0
而h函数!折叠到上一级(下一级)
“在当前位置设置标记“f”
执行“normal!mf”
“递归关闭所有文件夹
执行“正常!ggVGzC“
“打开所有级别较小的文件夹
设h=0
当我做zR
然后:设置foldlevel=2
时,我发现嵌入2(3和更深)的所有褶皱也都是闭合的。我只想关闭级别2。当我关闭zR
时,然后:设置foldlevel=2
我发现嵌入2(3和更深)中的所有折叠也关闭了。我只想接近2级。效果很好!我不得不删除这些评论,因为Vim没有意识到它们是出于某种原因的评论。但是成功了@内古茹是我的错。我改了一点,现在你可以呆在原地了。太棒了!我不得不删除这些评论,因为Vim没有意识到它们是出于某种原因的评论。但是成功了@内古茹是我的错。我稍微改变一下,现在你可以呆在原地了。
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>)