Reputation:
I am using vim to write Markdown. When I type this:
1. test
2. test
Vim is annoying and formats it to this:
1. test 2. test
My formatoptions
(tqlna
) do include n
. The filetype is markdown
. The formatlistpat is the following:
setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+
Part of it seems to work because Vim understands that it should not reformat lists beginning with -
, *
or +
.
How can I fix this?
Upvotes: 4
Views: 1385
Reputation:
For some reason want
as formatoptions
seems to fix the problem. I'm not able to explain why, though. I knew w
prevented the behavior I complained about, but I wasn't happy with this solution because then the auto-formatting of normal paragraphs was a bit funky. want
, which I'd never tried, seems to take care of everything and makes Vim behave like a normal modern soft-wrapped text editor.
I got the idea from this website: http://blog.ezyang.com/2010/03/vim-textwidth/
"I find fo=want to be useful when working on RST documents or emails. Easy mnemonic, too."
Upvotes: 0
Reputation: 31070
If I'm right then vim is actually not recognizing lines starting with +
but only *
and -
. Unfortunately this is due to vim's internal formatter (the gq
command uses this formatter). The a
option in your formatoptions
tells vim to automatically use the internal formatter as you're typing, and this is what's screwing everything up.
If you take the n
option off and leave your formatlistpat
then should wrap appropriately when you reach the end of textwidth
while typing. However, the second you try to format your file with gq
it will screw it up again.
It looks like what you need is a formatprg
that formats markdown files in the way you prefer. Then you can set that and leave the a
option on for automatic formatting. Until you find one I suggest just removing the a
from your formatoptions
and not using gq
to format your file.
You might also want to match for possible whitespace before the [-*+]
in your pattern. For example,
setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^\\s*[-*+]\\s\\+
Upvotes: 2