2012-01-24 20 views
9

vimのfoldmethodをインデントに設定しました。これは、コメント行がある場合を除いて、Pythonを書くときにうまくいきます。例えば、私はこのコードのビットを持っている場合:vimでPythonのコメント行を含むインデントを適切にインデントする方法を教えてください。

def myFunction(): 
    # here is my comment 
    myString = "hello" 
    myInt = 2 

私はコメント行に私のカーソルを持っていると私はというエラーを取得し得る「ZA」と入力すると「E490:いいえ倍が見つかりません」私はこの倍を取得したいと思いますどちらの場合も

def myFunction(): 
    # here is my comment 
+--- 2 lines: myString = "hello" ------------------------- 

def myFunction(): 
+--- 3 lines: # here is my comment ------------------------- 

基本的にはコメント行Iは「のmyString =」私はこのように折り畳ま下駄うで始まる行にカーソルを持っている場合他の何かのように扱われるべきです。私はウェブを検索して答えを出さなかった。何か案は?ありがとう!

答えて

14

foldignoreには何も設定しないでください。 :help foldignoreから

:set foldignore= 

'foldignore' 'fdi' string (default: "#") 

    Used only when 'foldmethod' is "indent". Lines starting with 
    characters in 'foldignore' will get their fold level from surrounding 
    lines. White space is skipped before checking for this character. 
    The default "#" works well for C programs. See |fold-indent|. 
3

:help fold-indentから:

一部の行は無視され、最も低いものは何でも上またはその下の行、 の倍のレベルを取得しています。これらは空白または白線で、 を開始する行で、 'foldignore'に文字が入ります。空白は、 'foldignore'内の 文字をチェックする前にスキップされます。 Cでは "#"を使用してプリプロセッサの行を無視します。

少なくとも私のvimでは、foldignoreは文字 '#'に設定されています。

:set foldignore= 

のようなコマンドを入力して空にしてください。

関連する問題