2016-05-10 10 views
1

vim Einzüge Listen (oder Kugeln) in Textdateien fein:vim: Einrücken Kugel/Listen innerhalb von Kommentaren (in Python)

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

I gqap innerhalb des Absatzes oben eingeben kann, und die Formatierung und Einrücken Arbeit richtig .

Allerdings funktioniert das nicht innerhalb Python Kommentare, und wird wie so zerklüftet:

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

Wenn ich gqap im Python Kommentar oben eingeben, nicht vim nicht einmal die folgenden Punkte erkennen. und endet die Formatierung des gesamten Blocks in einem Paragraph.

Also wie bekomme ich in Bezug auf Aufzählungszeichen und Einrückung vim, sich in Python-Kommentaren genauso zu verhalten wie in einer normalen Textdatei?

Antwort

2

Dies ist eigentlich ein ziemlich schweres Problem, das nicht offensichtlich dokumentiert ist, obwohl es sehr gut von formatlistpat unterstützt wird. Ich war in der Lage, mehrere Arten von Listen zu unterstützen, indem ich formatlistpat und formatoptions als die Einstellungen identifizierte, mit denen ich in meinem vimrc spielen wollte.

Sie können eine vollständige Übersicht mit den folgenden erhalten:

:help 'formatlistpat' 
:help 'formatoptions' 

Ihr Arbeitsbeispiel zeigt an, dass Sie wie die Art und Weise, dass vim die folgende verwandelt:

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

Durch Eingabe gqap oder gqip in Normaler Modus erhalten Sie folgendes:

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

Aber t hier ist ein Problem, dass Sie in vim mit Ihrer Konfiguration nicht indent unorder Listen können, wenn Sie mit so etwas wie die folgende angezeigt werden:

# - 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 

In diesem Fall gpaq falsch an folgenden formatieren

Sie können sofort diese Vertiefung Problem beheben mit dem folgenden:

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

Welche umformatieren wird Ihr Kommentar in der Art und Weise, dass Sie beabsichtigen:

# - 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 

Es gibt auch andere Listen, die Sie auch unterstützen wollen ja:

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

wie folgt zusammen:

# 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 

korrekt formatiert werden kann:

# 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 

Kann richtig formatiert werden mit:

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

Die folgende:

# 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 

korrekt formatiert werden können:

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

können Sie, dass alle zusammen mit zwei einfachen Linien setzen:

:set formatoptions+=n 
:set formatlistpat=^\\s*\\w\\+[.\)]\\s\\+\\\\|^\\s*[\\-\\+\\*]\\+\\s\\+