Is there a way to format text in Vim that relates to underlined headers?
Markdown has two ways of representing headers:
#Level 1 heading ##Level 2 heading ###Level 3 heading
and only for levels 1 and 2:
Level 1 heading
I am fond of underlining, because, in my opinion, it reads better.
When I compose a markdown in Vim with, say :set textwidth=72 , I would like to be able to reformat the entire document with gggqG , but it treats these underlined headings as paragraphs and compresses them together on one line. Therefore, if I started with the following:
Lorem ipsum =========== Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
After running gq all the way through, I get something like this:
Lorem ipsum =========== Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Is there a way to prevent the formatting of selected Vim headers?
I suppose there should be a solution using formatexpr or formatprg . I studied the documentation for par , and although it is very powerful, it seems that this is not one of its functions. Therefore, I wonder if there is another external program that can be used with formatprg that understands markdowns, or if this can be achieved instead of using vimscript with the formatexpr parameter.
vim formatting markdown text-formatting
nelstrom
source share