2

foldmethod=syntax を使用しているときに、小さな折り畳み (<10 行) を自動的に展開する方法はありますか?

使用するオプションがあることを理解しています

set foldminlines=10

でも、この設定だと、後で折りたいと思っても折ることができません。

編集

Ingo Karkatのおかげで、私の設定はやりたいことができるようになりました。

au BufReadPre * if !exists('b:folddict') | let b:folddict = {} | endif
function! s:UnfoldSmallFolds( count )
  if empty(b:folddict)
    "fill list
    let l:_none = s:checkInnerFolds(['1',line('$')], a:count)
  else
    "folddict should be filled by now
    " check if lnum is in fold
    let l:index = s:checkFoldIndex(keys(b:folddict), getpos('.')[1])
    if l:index != 0
      "check if open -> close
      if b:folddict[l:index] == 1
        foldclose
        let b:folddict[l:index] = 0
      else
        foldopen
        let b:folddict[l:index] = 1
        let l:_none = s:checkInnerFolds(split(l:index,'-'),a:count)
      endif
    endif
  endif
endfunction

function! s:checkInnerFolds(index,count)
  let l:lnum = a:index[0]
  while l:lnum <= a:index[1]
    if foldclosed(l:lnum) == -1
      let l:lnum += 1
      continue
    endif

    let l:endLnum = foldclosedend(l:lnum)
    let l:innerIndex = l:lnum."-".l:endLnum
    if has_key(b:folddict,l:innerIndex)
      if b:folddict[l:innerIndex] == 1
        foldopen
        let l:_none = s:checkInnerFolds(l:innerIndex,a:count)
      endif
    else                        
      let b:folddict[l:innerIndex] = 0
      if l:endLnum - l:lnum < a:count
        execute printf('%d,%dfoldopen!', l:lnum, l:endLnum)
        let b:folddict[l:innerIndex] = 1
        let l:_none = s:checkInnerFolds(l:innerIndex,a:count)
      endif
    endif
    let l:lnum = l:endLnum + 1
  endwhile
endfunction


function! s:checkFoldIndex(folds, pos)
  let l:retLine = ['0','0']
  for line in a:folds
    let l:splitLine = split(line,'-')
    if a:pos >= l:splitLine[0] && a:pos <= l:splitLine[1]
      if a:pos-l:splitLine[0] < a:pos-l:retLine[0]
        let l:retLine = l:splitLine
      endif
    endif
  endfor
  return join(l:retLine,"-")
endfunction 
4

1 に答える 1