list - VIM 中的格式化列表

标签 list vim formatting

我想找到一种在 Vim 中轻松格式化列表的方法。
我检查了 PAR 和 Vim 的默认格式化程序。

p.e.

1. this is my text this is my text this is my text 
2. this is my text this is my text this is my text 
3. this is my text this is my text this is my text 
4. this is my text this is my text this is my text  

还有这个

- this is my text this is my text this is my text 
- this is my text this is my text this is my text 
- this is my text this is my text this is my text 
- this is my text this is my text this is my text  

当我选择行并使用 PAR 和 VIM 将默认格式设置为 42 时,结果如下:


编号列表

用 par 格式化:
标准错误:
(42) <= (0) + (50)

用 vim 格式化:

1. this is my text this is my text this is
my text 
2. this is my text this is my text this is
my text 
3. this is my text this is my text this is
my text 
4. this is my text this is my text this is
   my text 

带有'-'的列表

用 par 格式化:
过滤了 4 行(无变化)

用 vim 格式化:

- this is my text this is my text this is
  my text 
- this is my text this is my text this is
  my text 
- this is my text this is my text this is
  my text 
- this is my text this is my text this is
  my text 


Vim 在格式化列表方面做得更好,但在编号列表中也不正确。
即使我像这样使用前缀 ("p") 选项,Par 在格式化列表时也会遇到很多麻烦:
'<,'>!par w42p4dh 或 '<,'>!par w42p3dh

有没有人知道如何毫无问题地格式化列表的好方法?

最佳答案

尝试设置fo+=n。来自 :help fo-table:

n       When formatting text, recognize numbered lists.  This actually uses
        the 'formatlistpat' option, thus any kind of list can be used.  The
        indent of the text after the number is used for the next line.  The
        default is to find a number, optionally followed by '.', ':', ')',
        ']' or '}'.  Note that 'autoindent' must be set too.  Doesn't work
        well together with "2".                    

        Example: 
                1. the first item
                   wraps 
                2. the second item   

关于list - VIM 中的格式化列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6731794/

相关文章:

formatting - 不显示文化的本国货币时的正确货币格式

javascript - 删除 Google 文档中的空行

java - 同步与 Collection.synchronizedList 与 CopyOnWriteArrayList

c++ - 将一个类的列表添加到另一个类

Vim - 在键盘映射中发送标签键击

shell - 如何在 vim 中运行 shell 命令并将结果字符串返回到 VimScript 变量中?

html - vim 中非标准元素的缩进和语法

Python:创建由字符串组成的列表的高效语法

python - 如何计算列表列表并返回 float 列表

formatting - VSCode:如何在保存时自动格式化?