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
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.![]()
Hm. That doesn't make sense to me, on multiple levels:
a format option causes long lines to hard wrap, which is not the desired behavior I described.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
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.![]()
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.![]()
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.![]()
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.![]()
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.![]()
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.![]()
@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.![]()
@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.![]()
@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.![]()
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.![]()
@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.![]()
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.![]()
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.![]()
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.![]()
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.![]()
@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.![]()
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.![]()
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.![]()
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):

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(®match, 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.![]()
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.![]()
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.![]()
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.
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.![]()
yeah, I changed it to use the 'formatlistpat' option instead. Good hint.