2016-05-10 18 views
1

のvimのインデントリスト(または箇条書き)テキストファイル内の罰金:VIM:コメントの中に箇条書き/リストをインデント(Pythonで)

- this is item one that 
    is indented correctly 
- this is item two that 
    is also indented 
    correctly 

私は上の段落、および書式内gqapを入力し、正しく作業をインデントすることができます。

しかし、これはPythonのコメントの中には動作しませんし、そうのようにインデントされます:私は上記のpythonコメント内gqap入力

# - this is item one that 
# is not indented correctly 
# - this is item two that 
# is also not indented 
# correctly 

場合は、vimのも、箇条書きを認識しません。ブロック全体をパラグアフにフォーマットします。

弾丸とインデントに関しては、普通のテキストファイルと同じように、vimにPythonのコメントの中で同じように動作させるにはどうしますか?

答えて

2

これは実際にはformatlistpatによって非常にうまくサポートされていますが、明らかに文書化されていないかなり難しい問題です。私は自分のvimrcで再生したい設定として、formatlistpatとformatoptionsを特定するだけで、複数のスタイルのリストをサポートすることができました。

次との完全な概要を取得することができますにgqapまたはgqipを入力することにより

- this is item one that 
is indented correctly 
- this is item two that 
is also indented 
correctly 

:help 'formatlistpat' 
:help 'formatoptions' 

あなたの作業例では、Vimは以下の を変換する方法を好むことを示しています通常モードでは次のようになります。

- this is item one that is indented correctly 
- this is item two that is also indented correctly 

しかし、あなたは、次のようなものが提示されている場合は、ここにあなたがあなたの構成でのvimでインデントunorderリストをことができないという問題がある:

gpaqが誤って次のようにフォーマットされます。この場合
# - this is item one that 
# is not indented correctly 
# - this is item two that 
# is also not indented 
# correctly 
# + this is item one that 
# is not indented correctly 
# + this is item two that 
# is also not indented 
# correctly 
# * this is item one that 
# is not indented correctly 
# * this is item two that 
# is also not indented 
# correctly 

# - this is item one that is not indented correctly - this is item two that 
# is also not indented correctly + this is item one that is not 
# indented correctly + this is item two that is also not indented 
# correctly * this is item one that is not indented correctly * this 
# is item two that is also not indented correctly 

あなたはすぐに次のように、このインデントの問題を修正することができます。再フォーマットします

:set formatoptions+=n 
:set formatlistpat=^\\s*[\\-\\+\\*]\\+\\s\\+ 

をあなたのコメントは、あなたが意図した方法で:

# - this is item one that is not indented correctly 
# - this is item two that is also not indented correctly 
# + this is item one that is not indented correctly 
# + this is item two that is also not indented correctly 
# * this is item one that is not indented correctly 
# * this is item two that is also not indented correctly 

あなたもサポートしたいいや、他のリストがあります:

# a) this is item one that is not 
# indented correctly 
# b) this is item two that is also not 
# indented correctly 
# C. this is item three that is also not 
# indented correctly 

は正確でフォーマットすることができます:

:set formatlistpat=^\\s*\\w[.\)]\\s\\+ 

次:

# 1 this is item one that 
# is not indented correctly 
# 2) this is item two that 
# is also not indented 
# correctly 
# 33. this is item three that 
# is also not indented 
# correctly 

正確でフォーマットすることができます。

:set formatlistpat=^\\s*\\d\\+[.\)]\\s\\+ 

# i. this is item one that 
# is not indented correctly 
# ii. this is item two that 
# is also not indented 
# correctly 
# iv) this is item three that 
# is also not indented 
# correctly 

は正確でフォーマットすることができます。

:set formatlistpat=^\\s*[ivxIVX]\\+[.\)]\\s\\+ 

次の2本のシンプルなラインと一緒にそのすべてに置くことができます。

:set formatoptions+=n 
:set formatlistpat=^\\s*\\w\\+[.\)]\\s\\+\\\\|^\\s*[\\-\\+\\*]\\+\\s\\+ 
関連する問題