1

foldmethod=indent次のようにコードを折りたたむときに andを使用します。

def cake():
    #cake!
    print( "cake" )
    print( "for" )
    print( "you" )

そうですか

def cake():
    #cake!
    print( "cake" ) +++ 3 lines folded

でも見たい

def cake(): +++ 5 lines folded

このように最初の行 ( ) まで折りたたむ方法はありdef cake():ますか?

4

2 に答える 2

2

Learn Vimscript the Hard Way48章と49章では、代わりに. 基本的に、カスタムの ftplugin を作成し、その中に折りたたみスクリプトを入れる必要があります。スクリプトには、各行に必要な折りレベルを決定するために使用される関数が含まれています。foldmethod=exprindent

運が良ければ、これらの 2 つの章で提供されているサンプル コードは、Python と同様に空白に敏感な Potion 言語用のものであるため、Python に適応させるのは非常に簡単なはずです。.vim/after/ftplugin/pythonVimにはすでにPythonのftpluginが付属しているので、サイトに記載されている折りたたみスクリプトを の代わりに入れてもいいと思います.vim/ftplugin/potion

于 2013-07-11T17:59:51.270 に答える
1

このチュートリアルを使用してこれを解決しました。

これは関数の完成した束です:

fu! Indent_level(lnum)
  return indent(a:lnum) / &shiftwidth
  endfunction

fu! Next_non_blank_line(lnum)
  let numlines = line('$')
  let current = a:lnum + 1

  while current <= numlines
    if getline(current) =~? '\v\S'
      return current
      endif
    let current += 1
    endwhile
  return -2
  endfunction

fu! Custom_fold_expr(lnum)
  if getline(a:lnum) =~? '\v^\s*$'
    return '-1'
    endif

  let this_indent = Indent_level(a:lnum)
  let next_indent = Indent_level(Next_non_blank_line(a:lnum))

  if next_indent == this_indent
    return this_indent
  elseif next_indent < this_indent
    return this_indent
  elseif next_indent > this_indent
    return '>' . next_indent
    endif
  endf

set foldexpr=Custom_fold_expr(v:lnum)
foldmethod=expr

この投稿の「終了」マーカーのインデントを編集しないでくださいvimrc

于 2013-07-11T18:03:50.227 に答える