13

Basically, I'd like to have long entries for bulleted / numbered lists that automatically indent like so:

1. Congress shall make no law respecting an establishment of 
   religion, or prohibiting the free exercise thereof; or 
   abridging the freedom of speech, or of the press; or the 
   right of the people peaceably to assemble, and to petition 
   the government for a redress of grievances.

I'm aware that formatoptions=n will do this for numbered lists and formatoptions=c will do this for asterisks (provided they are defined as comment leaders with comments=fb:*), but this only works by forcing an automatic hard wrap. I'd prefer to avoid this situation, since in order to edit the paragraph, I then have to manually Join the lines back into one, make the edits, and then gqq to reformat.

The breakindent setting gets me halfway there, with automatic indentation for softwrapped paragraphs, but it only provides indentation identical to the first line. Is there any setting that combines breakindent's softwrap support with formatoptions+=cn's numbered- and bulleted-list recognition?

3
  • 2
    Afaik, this is not possible (compare also :h 'breakindentopt'). I think you have to create a feature request either on the vim_dev mailing list or on the issue tracker on github.
    – Hotschke
    Apr 26, 2017 at 12:06
  • For anyone who stumbles on this question in the future: The GitHub feature request is here; if you're a C programmer, we'd sure appreciate your help in building this feature, and if you're just a mere mortal, maybe you can at least chime in and state your support for it? :)
    – Ryan Lue
    Apr 19, 2019 at 7:00
  • I’m fairly certain I just edit the paragraph and do gqap (or something more fine-grained), no joining first
    – D. Ben Knoble
    Mar 2, 2021 at 14:43

2 Answers 2

3

As of Vim 8.2.0139, there are no configuration options to specify this behaviour. Furthermore, any changes to the behaviour of Vim's soft wrapping via 'wrap' will require implementing in the source code: there is no workaround possible by using Vimscript.*

See the feature request that Ryan Lue (who asked this question) added to the Vim project's issue tracker after brief discussion in the comments.

As of January 21st 2020, this issue remains open.

* Except, I guess, an extremely hacky and difficult-to-implement-properly one which worked by actually using hard-wrapping and converting to soft-wrapping on save.

1

This behaviour has been requested somewhat intermittently in various contexts [1], but so far (March 2021; vim 8.2, NeoVim 0.4.4) there doesn't seem to be a reasonable way to achieve this.

If this feature would benefit you, please upvote/comment on the GitHub feature request for vim (still open as of March 2021) and also for the corresponding one for NeoVim.


I use showbreak which is less than satisfactory but still, for me, makes my markdown more readable than nothing. Using:

set textwidth=0
set wrap
set linebreak  " wrap line at word boundaries
set breakindent
set showbreak=\ \ " note: \_\_, _ = <white space character>

Will produce (line numbers included to reveal the softwraps):

  1 * unordered lists
  2 * with a long line will
      break OK.
  3   * ...also when they are
        nested.
  4
  5 Non-lists will get a
      hanging indentation as        
      well though.
  6
  8 1. lists with any bullet
      wider than 1 character        
      won't be perfectly
      aligned.
  9 10. Even more-so when the
      bullet width varies
      within the list.

Something similar could probably be achieved using breakindentopt with min and shift.

With hard line breaks there seem to be various ways (e.g. plugin bullets.vim, see issue #38). Hard line breaks however is totally against my philosophy when it comes to Markdown and prose/flowing text.


[1]:

1
  • 1
    …and the feature has just made its way into both Vim (a month ago) and NeoVim (today)! Aug 9, 2021 at 18:16

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.