這是不平凡的;我用一個遞歸函數解決了這個問題,該函數決定了嵌套的級別,然後關閉最內層的摺疊。
" [count]zy Unfold all folds containing a fold/containing at least
" [count] levels of folds. Like |zr|, but counting from
" the inside-out. Useful to obtain an outline of the Vim
" buffer that shows the overall structure while hiding the
" details.
function! s:FoldOutlineRecurse(count, startLnum, endLnum)
silent! keepjumps normal! zozj
if line('.') > a:endLnum
" We've moved out of the current parent fold.
" Thus, there are no contained folds, and this one should be closed.
execute a:startLnum . 'foldclose'
return [0, 1]
elseif line('.') == a:startLnum && foldclosed('.') == -1
" We've arrived at the last fold in the buffer.
execute a:startLnum . 'foldclose'
return [1, 1]
else
let l:nestLevelMax = 0
let l:isDone = 0
while ! l:isDone && line('.') <= a:endLnum
let l:endOfFold = foldclosedend('.')
let l:endOfFold = (l:endOfFold == -1 ? line('$') : l:endOfFold)
let [l:isDone, l:nestLevel] = s:FoldOutlineRecurse(a:count, line('.'), l:endOfFold)
if l:nestLevel > l:nestLevelMax
let l:nestLevelMax = l:nestLevel
endif
endwhile
if l:nestLevelMax < a:count
execute a:startLnum . 'foldclose'
endif
return [l:isDone, l:nestLevelMax + 1]
endif
endfunction
function! s:FoldOutline(count)
let l:save_view = winsaveview()
try
call cursor(1, 0)
keepjumps normal! zM
call s:FoldOutlineRecurse(a:count, 1, line('$'))
catch /^Vim\%((\a\+)\)\=:E490:/ " E490: No fold found
" Ignore, like zr, zm, ...
finally
call winrestview(l:save_view)
endtry
endfunction
nnoremap <silent> zy :<C-u>call <SID>FoldOutline(v:count1)<CR>
你能舉一個我們的例子嗎 –
我編輯了我的問題。 – mrtnmgs