3

I have this markdown text:

* Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. 

actual result: After pressing gq on this bullet point, its reformatted into the following:

* Lorem Ipsum is simply dummy text of the printing and typesetting industry.
* Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
* when an unknown printer took a galley of type and scrambled it to make a type
* specimen book.

desired result: But instead, i would like to have the following result:

* Lorem Ipsum is simply dummy text of the printing and typesetting industry.
  Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
  when an unknown printer took a galley of type and scrambled it to make a
  type specimen book. 

How can i achieve that? I have already played around with :h fo-table and : h formatexpr but i haven't found sth useful.

1 Answer 1

4
+50

By default, the asterisk is one of the comment leaders, and the formatoptions setting defaults to having c and q in it. The q and comments is what you are running into. You can remove q from formatoptions like this:

set fo-=q

or unset the comment leaders:

set comments=

(note: no space or anything after the equals)

You can set up your vimrc (or equivalent in neovim) to apply one of those automatically when opening markdown. For example, if your markdown files end in '.md':

au BufNewFile,BufRead *.md set comments=

In my Vim setup, opening '.md' files loads a filetype handler for markdown (written by Tim Pope) that sets some better options, which indents your example line like you'd expect for a list. These settings are:

formatoptions=tcqln
comments=fb:*,fb:-,fb:+,n:>

Which you can likewise load in your vimrc (if you don't want to get the markdown type stuff) like this:

au BufNewFile,BufRead *.md set comments=fb:*,fb:-,fb:+,n:> formatoptions=tcqln

The ftplugin does even more, and includes syntax highlighting. It can be had at https://github.com/tpope/vim-markdown. I have not tried to see if it works with neovim.

4
  • I'll try installing neovim when I get home tonight to verify this against it.
    – John O'M.
    Apr 18, 2017 at 19:14
  • Note: it seems that github.com/plasticboy/vim-markdown was concealing something here. Without this plugin, your answer works. Enabling plasticboy's plugin produces the above error.
    – toogley
    Apr 18, 2017 at 20:20
  • (whether i disable or not comments=fb:*,fb:-,fb:+,n:> makes no difference). Still the answer helps.
    – toogley
    Apr 18, 2017 at 21:00
  • I've finally gotten neovim-0.1.7 installed, and I tried the plasticboy vim-markdown plugin instead of tpopes, and it seems to work the way you'd expect. I'm not currently able to reproduce the behavior you see. What other plugins do you have installed?
    – John O'M.
    Apr 19, 2017 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.