在 VIM 中格式化列表

发布于 2024-11-24 22:07:25 字数 1558 浏览 0 评论 0原文

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

pe

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 时,结果如下:


NUMBERED LIST

formatting with 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 

带 '-' 的 LIST

使用 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 does a better job formatting lists but it is not correct as well in a numbered list.
Par does have a lot of troubles formatting lists even when I use the prefix ("p") option like this:
'<,'>!par w42p4dh or '<,'>!par w42p3dh

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

I would like to find a way to easy format lists in Vim.
I checked PAR and the default formatter of 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  

and this

- 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  

when I select the lines and do a default format to 42 with PAR and VIM these are the results:


NUMBERED LIST

formatting with par:
par error:
(42) <= (0) + (50)

formatting with 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 

LIST with '-'

formatting with par:
4 lines filtered (no change)

formatting with 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 does a better job formatting lists but it is not correct as well in a numbered list.
Par does have a lot of troubles formatting lists even when I use the prefix ("p") option like this:
'<,'>!par w42p4dh or '<,'>!par w42p3dh

Does anyone know a good way how to format lists without problems?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨曦÷微暖 2024-12-01 22:07:25

尝试设置 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   

Try set fo+=n. From :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   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文