代码之家  ›  专栏  ›  技术社区  ›  Byron Hawkins

vim缩进:禁用枚举列表的推断

  •  0
  • Byron Hawkins  · 技术社区  · 7 年前

    在vim中,当我使用 gqip

    原始段落:

    Here is some text including a number
    3 in the paragraph, which may be
    regarded as the start of a numbered
    list when I format it. 
    

    ):

    Here is some text including a number
    3 in the paragraph, which may be
      regarded as the start of a numbered
    list when I format it. 
    

    问题是,vim将单词“视为”对齐,就像第段中的行“3…”不知怎的,意思是“(3)在段落中”。在我看来,这是格式规则中的一个缺陷,因为在普通文本中经常出现明显的反例。那么,我如何改进这个缩进规则,使其仅适用于数字上有类似列表的标点符号的情况呢?例如,我认为这是可以的:

    Here is some text including a number
    3) in the paragraph, which may be
       regarded as the start of a numbered
    list when I format it. 
    

    这条规则也有反例,但至少错误发生的频率较低。可以通过检查平衡括号来进一步完善该规则,即:

    Here is some text (including a number
    3) in the paragraph, which is not
    regarded as the start of a numbered
    list when I format it (because the 
    parenthesis is accounted for by the
    opening parenthesis on line 1). 
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   leaf    7 年前

    看见 :h fo-table n 字母的意思,然后看 :h formatlistpat

    " 'formatlistpat' 'flp' string (default: "^\s*\d\+[\]:.)}\t ]\s*")
    
    " ignore '3 ' by removing space in pattern
    let &formatlistpat='^\s*\d\+[\]:.)}\t]\s*'
    
    " ignore (\n3) or [\n3] or {\n3} by adding a preceding NOT match
    let &formatlistpat='\([\[({]\s*\n\)\@<!\_^\s*\d\+[\]:.)}\t]\s*'