如何使Vim缩进列表项中的所有行-而不仅仅是第二行?


17

nVim的的选项formatoptions设置将缩进列表项的第二行以匹配第一行的缩进。但是,第三行及其后的行不还原为缩进,因此:

1. Doing a list. This is my list. I am writing
   a list. It's quite a long list. It's really
long. I can't believe how long it is. And
this just the first item!

2. Another list item.

我真的希望它缩进所有行,如下所示:

1. Doing a list. This is my list. I am writing
   a list. It's quite a long list. It's really
   long. I can't believe how long it is. And
   this just the first item!

2. Another list item.

使用Vim自己的选项,脚本或外部格式化程序(例如par),是否可行?

Answers:


16

我认为只需设置“自动缩进”即可解决该问题。它为我做。

set ai


2
对我也适用,并且我不自己弄清楚它而感到愚蠢,尤其是看到它位于'n'设置的文档中时!谢谢。
Rich

@akira是的 我是一个白痴。我认为我的困惑是因为Vim在缩进第二行,所以我以为我已经autoindent打开了,问题中描述的行为是设计的行为。我确实认为该手册的措词可能更清楚,以使像我这样的白痴受益。:)
Rich

有关更深入的解决方案,请参见@akira的答案
克林特·帕奇

5

在您的情况下,我会这样做:

 :set autoindent       " just for interactive indenting (see answer of @Rich) 
 :set fo+=2n           " :help fo-table
 :set tw=47            " your text shall wrap at xyz

(这tw=47对..很重要),然后按gqap

注意:我无法用=任何一种来使paragrap缩进,也许其他人知道了。


感谢您让我想起a p格式化线条的动议。我总是使用右大括号,这是相似的。别忘了您可以添加一个计数,例如,格式化以下三段:g q 3 }
克林特·帕奇
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.