Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrapping a bullet point inserts new bullet points #232

Closed
jefferai opened this issue Oct 21, 2015 · 11 comments
Closed

Rewrapping a bullet point inserts new bullet points #232

jefferai opened this issue Oct 21, 2015 · 11 comments

Comments

@jefferai
Copy link

I had a very long line starting with a bullet point. Without vim-markdown, selecting the text and rewrapping it via gq (to fit in 80 columns) causes the text to be wrapped mostly as expected (with some slight formatting glitches).

With vim-markdown installed, each of these new lines was preceded with an asterisk, causing each wrapped line to be an individual bullet point.

@jefferai
Copy link
Author

Strange. I tried it again after first wrapping the text without vim-markdown; in this case, vim-markdown correctly formatted it and did not add any new bullet points.

@jefferai
Copy link
Author

I played around with this some more; it seems like when rewrapping text that is already multi-line, it does the correct thing. However, if the text you want to wrap is currently a single long line, it turns each new line into a bullet point.

@cirosantilli
Copy link
Collaborator

Please provide a minimal example on the issue description so we an understand it faster ;-)

@jefferai
Copy link
Author

I'm not sure how to be clearer than I was. Make a long line starting with a bullet point:

* This is a long line that is preceded by an asterisk, e.g. a Markdown bullet point. When I wrap it bad things will happen.

Wrap it with vim-markdown installed:

* This is a long line that is preceded by an asterisk, e.g. a Markdown bullet
* point. When I wrap it bad things will happen.

Now you have two bullet points.

@alchemicalhydra
Copy link

Just ran into this; it only gets triggered when formatoptions includes q.

@timon
Copy link

timon commented Aug 18, 2016

When formatoptions includes t and textwidth is set, this happens each time VIM breaks long line.

@lemontheme
Copy link

lemontheme commented Sep 11, 2016

After a lot of trial and error, I was able to fix this by adding the following to my .vimrc.

autocmd FileType markdown 
    \ set formatoptions-=q |
    \ set formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^\\s*\[-*+]\\s\\+

Explanation:

  1. As @tomxtobin explains, q is a confusing factor, causing Vim to misidentify Markdown bullets as comment markers. So start by removing that from formatoptions.
  2. Markdown bullets are covered by formatlistpat, but – whether intentional or not – the current regex does not allow for indentation. Prefixing this part of formatlistpat with ^\\s* seems to have fixed the rest of the problem.

Disclaimer: I'm still relatively new to Vim. Just wanted to share this in case I'm not the only who one found this default something of a deal-breaker.

@andmatand
Copy link

lemontheme's solution does not seem to work for me; in fact, even just havingset formatoptions-=q present makes the next line's indentation too big, like this:

* This is a line and then when I use gq it
    wraps like this

This is in vim 8.0...maybe something has changed in the new version to cause this to no longer work?

@sersorrel
Copy link
Contributor

I think the comments option might be the root cause of this. I'm using Vim 8.1.20, and comments is set to b:*,b:+,b:-,b:> – removing the first three elements from that by setting it to just b:> seems to solve this issue, and avoids the extra indentation that @andmatand mentioned.

@sersorrel
Copy link
Contributor

sersorrel commented May 26, 2018

Turns out this issue was even noted on the buggy commit itself...

The basic problem is that the *, - and + characters are being treated like comment characters, but they are not used like comment characters. The feature is, afaik, intended for this style of comment:

/* asdf
 * some text
 * some more text
 */

but it's being misused for bulleted lists, which look something like this:

- foo bar
- some extreeeeeeeeeeeeeemely long text that
  is so long that it wraps
- some more text

Note that, in the code comment, every line starts with * and when Vim rewraps the comment, it should automatically insert and remove them as needed. But in the Markdown case, only some lines start with - and Vim should never insert or remove bullets automatically when rewrapping.

@dylan-chong
Copy link

dylan-chong commented Jun 3, 2018

@shirosaki This is still a problem! (Both the indenting problem in @andmatand 's comment and the auto inserting of bullet points) (see @anowlcalledjosh 's link) Will this get fixed anytime? This problem is very annoying!

serban added a commit to serban/dotfiles that referenced this issue Feb 6, 2022
plasticboy/vim-markdown `formatoptions`, `comments`, and `indentexpr`
lead to incorrect indentation and hard wrapping behavior as per:

* preservim/vim-markdown#232
  + Rewrapping a bullet point inserts new bullet points
* preservim/vim-markdown#390
  + gq wrapping is still broken

tpope/vim-markdown has the correct behavior. Compare the two
implementations:

* https://github.com/preservim/vim-markdown/blob/50d42082819cfa91745b6eff6e28ad5cbc8b27fa/indent/markdown.vim#L4
* https://github.com/tpope/vim-markdown/blob/891dff54a92b04cda36da7fbc6634831c3389d29/ftplugin/markdown.vim#L12

See also `formatlistpat` and explanations at:

* https://vimways.org/2018/formatting-lists-with-vim
* https://blog.siddharthkannan.in/2019/11/02/format-list-pat-and-vim

While I'm at it, introduce dkarter/bullets.vim to take my list game to
the next level.

Pro Tip: When switching back and forth between plasticboy/vim-markdown
and tpope/vim-markdown, use the following to keep vim-plug happy:

    Plug 'tpope/vim-markdown', {'as': 'tpope-markdown'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants