vim-pandoc-syntax icon indicating copy to clipboard operation
vim-pandoc-syntax copied to clipboard

Continuation indent for lists

Open addisonamiri opened this issue 9 years ago • 14 comments

I was wondering if it would be possible to introduce a continuation indent option for lists that are soft-wrapped across multiple lines. For instance right now it would be wrapped like:

- This is a really long sentence that wraps across
two lines.

I would like it to wrap like this

- This is a really long sentence that wraps across
  two lines

That way the bullet points stick out from the rest of the list. If this could be implemented for numbered lists as well that'd be nice.

addisonamiri avatar Jan 12 '16 21:01 addisonamiri

+1 I would also prefer this type of list indentation. Maybe it could be made an option and the current style could stay the default in case many still prefer that?

joelostblom avatar Mar 16 '16 17:03 joelostblom

Hm... I don't think this is possible in vim/nvim, at leas when using soft wrapping. breakindent (which vim-pandoc uses) does something like this, but as far as I know doesn't handle this case. I will take a look regardless, but independent research would be appreciated.

fmoralesc avatar Mar 16 '16 18:03 fmoralesc

Thanks for mentioning breakindent. I looked it up and found a way to set the indent as described above. You can test it by opening a vim file that has bullet point with soft line breaks and type set showbreak=\ \ (to be clear: that's two escaped spaces).

Sample bullets from the blog post I linked:

- So I wanted Vim to visually wrap long lines, but take the indentation of the line into account when it does so. Vim could not do that when I went looking in 2009, but as of June 25, 2014, Bram merged the breakindent feature.
- To get this behaviour, use set breakindent. You can combine it with set showbreak=.. or set showbreak=\ \ to provide a little bit of additional indent to the wrapped portion of the lines.
- For example, this shows vim with set breakindent showbreak=.., set linebreak, set foldmethod=indent foldcolumn=4 and set shiftwidth=4 tabstop=4 softtabstop=4 expandtab options with a visual highlight that wraps across lines: 

Normal vim-pandoc: screenshot from 2016-03-16 17-19-38

After set showbreak=\ \: screenshot from 2016-03-16 17-20-05

joelostblom avatar Mar 16 '16 21:03 joelostblom

Ok, feel free to open a PR, or I will add this when I get back home

El mié, mar 16, 2016 10:24 PM, joelostblom [email protected] escribió:

Thanks for mentioning breakindent. I looked it up and found a way https://retracile.net/wiki/VimBreakIndent to set the indent as described above. You can test it by opening a vim file that has bullet point with soft line breaks and type set showbreak=\ \ (to be clear: that's two escaped spaces).

Sample bullets from the blog post I linked:

  • So I wanted Vim to visually wrap long lines, but take the indentation of the line into account when it does so. Vim could not do that when I went looking in 2009, but as of June 25, 2014, Bram merged the breakindent feature.
  • To get this behaviour, use set breakindent. You can combine it with set showbreak=.. or set showbreak=\ \ to provide a little bit of additional indent to the wrapped portion of the lines.
  • For example, this shows vim with set breakindent showbreak=.., set linebreak, set foldmethod=indent foldcolumn=4 and set shiftwidth=4 tabstop=4 softtabstop=4 expandtab options with a visual highlight that wraps across lines:

Normal vim-pandoc: [image: screenshot from 2016-03-16 17-19-38] https://cloud.githubusercontent.com/assets/4560057/13829085/69bf7200-eb9b-11e5-92d2-3bfc714ed91a.png

After set showbreak=\ : [image: screenshot from 2016-03-16 17-20-05] https://cloud.githubusercontent.com/assets/4560057/13829084/69bc6d30-eb9b-11e5-8085-bffa103992c9.png

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/vim-pandoc/vim-pandoc-syntax/issues/161#issuecomment-197555239

fmoralesc avatar Mar 16 '16 21:03 fmoralesc

Sorry, I am not very good with vimscript so I am not sure how to apply this only to lines starting with a bullet. The default is to indent all soft wrapped lines.

joelostblom avatar Mar 16 '16 21:03 joelostblom

Ah, right! Hm, in that case there just might not be a good way of dealing with this. I can introduce a way to adjust the indent when entering and leaving a list, but it will still apply to the whole document. I was playing with setlocal breakindentopt=shift:2, which is similar, but it also has the same issue.

fmoralesc avatar Mar 16 '16 23:03 fmoralesc

Hmmm, I looked around a little and it seems like the breakindent feature was merged into vim in 2014. Before that, a few different patches existed that provided the same feature. The github page of one of those patches makes me hopeful that it will be possible to set a local breakindent:

BreakIndent Beta is a pure vimscript alternative to the old breakindent patch, which I failed to get working smoothly in modern Vim. Unlike the breakindent patch, this vimscript cannot present a different indent for each line. Instead it updates the showbreak option to fit the indent of the current cursor line.

From that passage, it seems to me that the "old breakindent patch", which I believe is the one that was later modified and implemented in vim by default, does have the functionality to present different indents for each line. However, my English understanding might be off here and I am not sure if I interpret it correctly. But we will hopefully find out soon, since I sent an email to the author of the current version of breakindent to see if it is at all possible.

joelostblom avatar Mar 17 '16 01:03 joelostblom

@joelostblom I didn't author the patch; I merely kept it up-to-date until it was integrated, and therefore did not have to fully grok it. That said, I'll try to explain what I can.

The breakindent patch wraps a line at the indentation level of that line, independent of the other lines in the document. To make it affect a line differently if that line's first non-whitespace character is -, would require code changes. I'd look at get_breakindent_win() as a starting point, and conditionally use its result if the line was for a bullet point, but that's mostly guesswork. If you want indentation-aware wrapping in all the document, but want 'extra' wrapping for the - lines, another approach might be to make a conditional showbreak-like function.

But that's hacking Vim at the source-code level, and I don't know if that fits the constraints you want to work within.

I hope something in that rambling proves useful.

retracile avatar Mar 17 '16 02:03 retracile

Thank you @retracile, for taking the time to share your thoughts. It will be up to @fmoralesc to decide what is within the scope of the vim-pandoc-syntax plugin, although it sounds to me like this might be too much work for a feature only requested by a couple of people. Thanks again for your input, I highly appreciate it.

joelostblom avatar Mar 17 '16 03:03 joelostblom

Yeah, @retracile is right there (I ported breakindent to neovim, so I had the same impression).

Again, it is possible to make the application of the adjustment to the shift context-dependent, but it will obviously not be the ideal case and it will make the document look weird in some cases. Another issue is that the amount of shifting necessary will ideally also have to be context-dependent; think of this case:

9) alka lkjdlakda dlak jlkdjla kjda kdla kjdlak
   k lajd kajldkja ldkja lkjdlakj ldkaj
10) lakjdlkajldkaj  lkjaldk jlakjlkjalkdjlak jdla
    dklakjldk jaldkjal kjda

fmoralesc avatar Mar 17 '16 05:03 fmoralesc

Yes, I agree, it could be confusing having the indent adjust for all lines when entering a list. And the double digit numbers would also be an issue (although I think a minor one since all single digit numbers and other bullets would work fine). So maybe it is not worthwhile spending time trying to implement this, if the final result still will not be what was suggested initially.

joelostblom avatar Mar 17 '16 14:03 joelostblom

@joelostblom , something would be better than nothing; lists can be difficult to identify and read without some sort of indentation. I believe this is a case of "perfect is the enemy of good:" even if list continuation alignment isn't perfectly aligned, some indentation to make it easier to visually distinguish list items would be "good enough" to improve readability.

ghost avatar Jun 12 '19 23:06 ghost

Just to mention that the plugin bullets.vim provides indentation for lists.

ErickChacon avatar Mar 25 '20 15:03 ErickChacon

Just to mention that the plugin bullets.vim provides indentation for lists.

Yes - but only for hard wraps, unfortunately not for soft wraps. See this dkarter/bullets.vim issue/discussiuon.

Also, unfortunately the set showbreak=\ \ trick suggested above breaks when activating the bullets.vim plugin.

For those that would like to see this implemented in vim/NeoVim (for soft line breaks), please upvote/comment on the GitHub feature request for vim (still open as of March 2021) and also for the corresponding one for NeoVim.

LeuschkeTressa avatar Mar 01 '21 18:03 LeuschkeTressa