[vim/vim] Feature Request: Hanging indent for numbered/bulleted lists (softwrapped) (#1661)

64 views
Skip to first unread message

Ryan Lue

unread,
Apr 27, 2017, 10:42:19 AM4/27/17
to vim/vim, Subscribed

I'd like to suggest a feature for smart indenting of soft-wrapped paragraphs, somewhat in the vein of breakindent – but rather than having the rest of the paragraph match the first (visual) line, to have it do a hanging indent on a bulleted/numbered list 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 posted about this on the vi/vim StackExchange over six months ago, so I'm fairly certain there's no way to accomplish this through vim's existing settings.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub

Matěj Cepl

unread,
Oct 29, 2019, 6:44:33 PM10/29/19
to vim/vim, Subscribed

That’s weird, with formatoptions=1jtroqlaw I get both intended lists and format=flowed-style paragraphs.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub, or unsubscribe.

Ryan Lue

unread,
Oct 29, 2019, 10:31:46 PM10/29/19
to vim/vim, Subscribed

Hm. That doesn't make sense to me, on multiple levels:

  1. The a format option causes long lines to hard wrap, which is not the desired behavior I described.
  2. None of the format options you mentioned have anything to do with lists.
  3. Not sure what "format=flowed" has to do with it—my understanding is that format=flowed manages blockquote/comment markers at the start of a line? (whereas my feature request is about paragraph indentation relative to a list marker.)


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub, or unsubscribe.

Ryan Lue

unread,
Oct 29, 2019, 10:32:30 PM10/29/19
to vim/vim, Subscribed

In any case, here is an asciinema cast of your format options not producing the behavior I'm asking about.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub, or unsubscribe.

Alan Young

unread,
Jan 16, 2020, 4:38:15 PM1/16/20
to vim/vim, Subscribed

I'd like to add my input and request, just in case it isn't implicit in the original request.

When writing comments (e.g., in a bash script) I would like to do the same thing. So, the above example text would look something like:

# 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.


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub, or unsubscribe.

Gary Johnson

unread,
Jan 16, 2020, 5:38:21 PM1/16/20
to reply+ACY5DGGW3X7X7SO5ZZ...@reply.github.com, vim...@googlegroups.com
On 2020-01-16, Alan Young wrote:
> I'd like to add my input and request, just in case it isn't implicit in the
> original request.
>
> When writing comments (e.g., in a bash script) I would like to do the same
> thing. So, the above example text would look something like:
>
> # 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.

Vim does this now. I have the following set for bash scripts.

comments=s1:/*,mb:*,ex:*/,b:#,:%,:XCOMM,n:>,fb:-
formatoptions=tcqrlnj1
autoindent
textwidth=78

Those are sufficient but might not all be necessary.

Regards,
Gary

vim-dev ML

unread,
Jan 16, 2020, 5:38:47 PM1/16/20
to vim/vim, vim-dev ML, Your activity
On 2020-01-16, Alan Young wrote:
> I'd like to add my input and request, just in case it isn't implicit in the
> original request.
>
> When writing comments (e.g., in a bash script) I would like to do the same
> thing. So, the above example text would look something like:
>
> # 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.


Vim does this now. I have the following set for bash scripts.

comments=s1:/*,mb:*,ex:*/,b:#,:%,:XCOMM,n:>,fb:-
formatoptions=tcqrlnj1
autoindent
textwidth=78

Those are sufficient but might not all be necessary.

Regards,
Gary


You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub, or unsubscribe.

Matěj Cepl

unread,
Jan 17, 2020, 5:16:45 AM1/17/20
to vim/vim, vim-dev ML, Comment

So, this ticket should be closed as already-resolved, right?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

K.Takata

unread,
Jan 17, 2020, 5:45:25 AM1/17/20
to vim/vim, vim-dev ML, Comment

It doesn't seem to fix @rlue's case.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

Matěj Cepl

unread,
Jan 17, 2020, 6:08:49 AM1/17/20
to vim/vim, vim-dev ML, Comment

I see! The problem is that we have this indentation in the indent/rst.vim file correctly. See https://github.com/marshallward/vim-restructuredtext/blob/master/indent/rst.vim#L29 for how it is done.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.

Ryan Lue

unread,
Jan 17, 2020, 11:01:25 AM1/17/20
to vim/vim, vim-dev ML, Mention

@mcepl, not sure your RST plugin is relevant to my feature request: I'm asking about soft wrapping, and you've linked to a function for 'indentexpr', which (afaik) sets indentation on individual lines (i.e., hard wrapping).

@vim-ml, I'm still not quite sure how to install the latest version of vim. I'm on Debian testing and am using the package provided with the distro, which is

VIM - Vi IMproved 8.1 (2018 May 18, compiled Nov 09 2019 12:59:40)
Included patches: 1-2269

In any case, the settings you provided appear to be for hard wrapping as well (again, afaik): textwidth=78 enables hard wrapping, where textwidth=0 would disable it.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Matěj Cepl

unread,
Jan 17, 2020, 11:04:46 AM1/17/20
to vim/vim, vim-dev ML, Mention

@mcepl, not sure your RST plugin is relevant to my feature request: I'm asking about soft wrapping, and you've linked to a function for 'indentexpr', which (afaik) sets indentation on individual lines (i.e., hard wrapping).

I don’t think so, without regards whether you have textwidth set or not, you need wrapping and indentation (provided by indent/ scripts) if you have wrap on. It is the same thing (and using the same code).


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Rich

unread,
Jan 17, 2020, 11:27:40 AM1/17/20
to vim/vim, vim-dev ML, Mention

@mcepl I think you (and also possibly @harleypig) are misunderstanding what this feature request is asking for. indentexpr and other indent options only affect the start of lines, and they work by changing the content of the file. @rlue is asking for an option that will affect the display of soft wrapped lines only, and it doesn't affect where the start of the lines are positioned: only the parts that wrap down onto the next line.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Tom M

unread,
Jan 17, 2020, 7:08:00 PM1/17/20
to vim/vim, vim-dev ML, Mention

How about using :set breakindent breakindentopt=min:5,shift:3, possibly with :set linebreak?

Tom


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Ryan Lue

unread,
Jan 18, 2020, 1:04:20 AM1/18/20
to vim/vim, vim-dev ML, Mention

@tom-m thanks for the suggestion. I haven't tested it, but according to my understanding, it breaks soft wrapping for everything but one-digit numbered lists. Regular paragraphs would get a hanging indent, and unordered lists (indicated by an asterisk/hyphen/etc.) would get a hanging indent one character wider than appropriate. Double-digit list items would have the wrong indent level, too.

Honestly, I've gotten more comfortable with hard wrapping plain text these days, so this isn't so much of a problem for me anymore. The StackExchange post I linked in my original comment does have nine upvotes, though, so I guess there are a few other people out there with their eye on this feature.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Chris Chernesky

unread,
Oct 25, 2020, 7:36:28 PM10/25/20
to vim/vim, vim-dev ML, Mention

I would love to see this implemented if at all possible. I tried the hard wrapping and it really doesn't work for my use case that well.

Right now, I'm "dealing" with the breakindent solution, but would love for this to be supported fully.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

LeuschkeTressa

unread,
Mar 1, 2021, 4:23:18 PM3/1/21
to vim/vim, vim-dev ML, Mention

I'd really like to see this feature as well. Markdown and free flowing text/prose really only works with soft wraps and reasonable list indentation is really key for the readability of text with lists/bullets. It's a pity that not even vim/neoVim is configurable enough that this can be achieved, not even with a custom plugin, as I understand it.

There is a similar feature request for NeoVim, with a contributor having stated that it is unlikely that NeoVim will implement it unless Vim implements it upstream.

Some requests for this feature:


My current workaround is using set showbreak=\ \ - less than satisfactory but better than nothing.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

rightaway

unread,
Jul 12, 2021, 10:26:52 AM7/12/21
to vim/vim, vim-dev ML, Mention

Are the maintainers interested in this feature request? Any way we can help?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Christian Brabandt

unread,
Jul 12, 2021, 11:45:42 AM7/12/21
to vim/vim, vim-dev ML, Mention

The best chance to have this feature available is providing a PR. I suppose this is for the breakindent feature only, so you may want to look into get_breakindent_win() in indent.c. It already gets a pointer to the start of the line, so one could check that one if it matches some kind of numbering.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Chris Chernesky

unread,
Jul 12, 2021, 11:47:34 AM7/12/21
to vim/vim, vim-dev ML, Mention

@chrisbra Unfortunately I'm not a C developer. Do you know of anyone with enough familiarity with C that could be contracted to help with that feature? I'd be glad to help organize funding if there could be some way of financially or otherwise helping to get this feature implemented.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Christian Brabandt

unread,
Jul 12, 2021, 11:49:13 AM7/12/21
to vim/vim, vim-dev ML, Mention

let me put it on my plate


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Chris Chernesky

unread,
Jul 12, 2021, 12:15:27 PM7/12/21
to vim/vim, vim-dev ML, Mention

Please let me know how I can help you in any way. Financially, testing, etc. I'm glad to help.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Christian Brabandt

unread,
Jul 12, 2021, 4:01:09 PM7/12/21
to vim/vim, vim-dev ML, Mention

okay, here is a very simple poc-patch: You need to use :set briopt+=list:3 to specify an additional indent for lines that match a list or numbering. Currently, it uses a hard-coded pattern of: ^#\?\s*\d\+\(\.[])]\)\? That means a line starting optionally by a #, followed by white space, followed by any number, optionally followed by . optionally followed by either a ] or a ). It might make sense, to allow to specify the pattern how to detect lists.

Here is a screen-shot (similar to the text by the OP):
image

Note, that when using lines that are commented (e.g. start with #, you need to adjust the additional indent pattern. That's because for a line like this:

    1) foobar some content

we add the additional indent (e.g. +3) on top to the current indent of the line (e.g. +4), so having a total soft-indent of 7 for the wrapped lines. However with lines like this:

#   1) foobar some commented out conent

we add the additional indent (e.g. +3) to the current indent of the line (in this case 0), so it does not line up with un-commented lines.

Was that understandable?

Here is the WIP patch:

diff --git a/src/indent.c b/src/indent.c
index a26344b7d..8c2fac740 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -854,6 +854,7 @@ briopt_check(win_T *wp)
     int                bri_shift = 0;
     long       bri_min = 20;
     int                bri_sbr = FALSE;
+    int                bri_list = 0;

     p = wp->w_p_briopt;
     while (*p != NUL)
@@ -874,6 +875,11 @@ briopt_check(win_T *wp)
            p += 3;
            bri_sbr = TRUE;
        }
+       else if (STRNCMP(p, "list:", 5) == 0)
+       {
+           p += 5;
+           bri_list = getdigits(&p);
+       }
        if (*p != ',' && *p != NUL)
            return FAIL;
        if (*p == ',')
@@ -883,6 +889,7 @@ briopt_check(win_T *wp)
     wp->w_briopt_shift = bri_shift;
     wp->w_briopt_min   = bri_min;
     wp->w_briopt_sbr   = bri_sbr;
+    wp->w_briopt_list  = bri_list;

     return OK;
 }
@@ -941,9 +948,23 @@ get_breakindent_win(
     // Add offset for number column, if 'n' is in 'cpoptions'
     bri += win_col_off2(wp);

+    // add additional indent for numbered lists
+    if (wp->w_briopt_list > 0)
+    {
+       regmatch_T          regmatch;
+       regmatch.regprog = vim_regcomp((char_u *)"^#\\?\\s*\\d\\+\\(\\.\\?[])]\\?\\)\\?",
+               RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
+       if (regmatch.regprog != NULL && vim_regexec(&regmatch, line, 0))
+       {
+           vim_regfree(regmatch.regprog);
+           bri += wp->w_briopt_list;
+       }
+    }
+
     // never indent past left window margin
     if (bri < 0)
        bri = 0;
+
     // always leave at least bri_min characters on the left,
     // if text width is sufficient
     else if (bri > eff_wwidth - wp->w_briopt_min)
diff --git a/src/structs.h b/src/structs.h
index f1f8f3258..5331183e1 100644
--- a/src/structs.h
+++ b/src/structs.h
@@ -3671,6 +3671,7 @@ struct window_S
     int                w_briopt_min;       // minimum width for breakindent
     int                w_briopt_shift;     // additional shift for breakindent
     int                w_briopt_sbr;       // sbr in 'briopt'
+    int                w_briopt_list;      // additional indent for lists
 #endif

     // transform a pointer to a "onebuf" option into a "allbuf" option


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Chris Chernesky

unread,
Jul 12, 2021, 4:06:09 PM7/12/21
to vim/vim, vim-dev ML, Mention

I'll try to build this in the next day or so. Thanks for the POC. Really appreciate it!


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

James McCoy

unread,
Jul 12, 2021, 4:07:17 PM7/12/21
to vim/vim, vim-dev ML, Mention

Currently, it uses a hard-coded pattern of: ^#?\s*\d+(.[])])? That means a line starting optionally by a #, followed by white space, followed by any number, optionally followed by . optionally followed by either a ] or a ). It might make sense, to allow to specify the pattern how to detect lists.

Should it use 'formatlistpat' for that?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Maxim Kim

unread,
Jul 13, 2021, 2:50:12 AM7/13/21
to vim/vim, vim-dev ML, Mention

Should it use 'formatlistpat' for that?

This is what I would expect -- now I do gqip to format lists (with no wrapping and proper formatlistpat) and it would be really convenient to preserve the same formatting with soft wrapping.

vim-gqq

BTW, @chrisbra, your # is/should be a commentstring in a proper patch, right?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.

Christian Brabandt

unread,
Jul 13, 2021, 3:34:31 AM7/13/21
to vim/vim, vim-dev ML, Mention

yeah, I changed it to use the 'formatlistpat' option instead. Good hint.

Bram Moolenaar

unread,
Jul 14, 2021, 2:00:57 PM7/14/21
to vim/vim, vim-dev ML, Mention

Closed #1661 via 4a0b85a.

Reply all
Reply to author
Forward
0 new messages