Byron Hawkins
Byron Hawkins

Reputation: 2705

vim indentation: disable inference of enumerated list

In vim, when I format the following paragraph in a plain text file using gqip, the formatter indents it like an enumerated list.

Original 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. 

Formatted (after 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. 

The problem is that vim aligns the word "regarded" as if the line "3 in the paragraph..." somehow means "(3) in the paragraph". In my opinion, this is a bug in the formatting rules, because there are obvious counter-examples that occur frequently in ordinary text. So how can I refine this indentation rule to apply only when there is list-like punctuation on the number? For example, I think this is ok:

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. 

There are counter-examples to this rule as well, but at least the error occurs less frequently. The rule could be further refined by checking for balanced parentheses--i.e.:

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). 

Upvotes: 0

Views: 54

Answers (1)

leaf
leaf

Reputation: 1764

See :h fo-table 's n letter meaning, then see :h formatlistpat, which is used to recogize a list header:

" '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*'

Upvotes: 1

Related Questions