回流段落缩进“>”在Vim

时间:2014-06-02 18:09:47

标签: vim formatting indentation reflow

我使用(g)Vim编辑电子邮件,我经常需要在缩进段落中重排长行,这些段落以>>>等开头。

例如,想象我的textwidth设置得很短:

> Line 1 is short.
> Line 2 is very long, really, I mean, far too long, what a mess.
> Line 3 not so.

当我使用{gq}之类的格式进行格式化时,这应该会变成:

> Line 1 is short. Line 2 is very 
> long, really, I mean, far too 
> long, what a mess. Line 3 not so.

我怎样才能做到这一点?

2 个答案:

答案 0 :(得分:2)

Vim内置了对此的支持。 Vim有一个选项formatoptions,允许你指定几个这样的东西。请查看:h fo-table了解详情。

对于您的具体查询,您可能希望添加set formatoptions+=q,但我更希望set formatoptions+=tcroq更好地处理此类格式。

fo-table中还有其他宝石,我个人使用此设置:set formatoptions=njtcroql

答案 1 :(得分:1)

我使用ftplugin来执行此操作:

set comments=fb:*,fb:-,b:>,b:>>,b:>>>,b:>>>>                                    
set autoindent 

第一行的最后一部分是操作发生的位置 - 这提供了>>>等的“注释块”前缀,以空格分隔。

这只会影响缩进的第4级,但如果需要,我可以添加更多。

顺便说一句,前两个意思是我很容易得到缩进列表:

* List item is very long, it
  just keeps going and going 
  and going
- And this one uses a dash as
  a bullet point

编辑:正如Dhruva Sagar所说,formatoptions将确定我是否可以使用{gq}格式化评论。以上只是说明了评论前缀是什么。

相关问题