vim缩进:禁用枚举列表的推断
vim indentation: disable inference of enumerated list
在 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.
格式化(在 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.
问题是 vim 对齐单词 "regarded" 就好像行“3 in the paragraph...”不知何故意味着“(3) in the paragraph”。在我看来,这是格式规则的一个错误,因为在普通文本中经常出现明显的反例。那么我如何改进这个缩进规则以仅在数字上有类似列表的标点符号时应用?比如我觉得这样还可以:
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).
见: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*'
在 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.
格式化(在 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.
问题是 vim 对齐单词 "regarded" 就好像行“3 in the paragraph...”不知何故意味着“(3) in the paragraph”。在我看来,这是格式规则的一个错误,因为在普通文本中经常出现明显的反例。那么我如何改进这个缩进规则以仅在数字上有类似列表的标点符号时应用?比如我觉得这样还可以:
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).
见: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*'