[vim/vim] RFE: Indent better when typing bullet lists in txt files (#8794)

13 views
Skip to first unread message

m1027

unread,
Aug 25, 2021, 7:08:26 AM8/25/21
to vim/vim, Subscribed

vim already detects a leading dash as bullet in txt files and can reformat a bullet list nicely (visual selection + gq).

But when actually typing in a long line, starting with a bullet (dash) and when the line break kicks in, the second row is indented as if there was no bullet.

Desired behaviour: When the line break kicks in, the next line should (optionally) start a little more to the right, just like gq does on paragraphs with leading dahes.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Enno

unread,
Aug 25, 2021, 10:14:05 AM8/25/21
to vim/vim, Subscribed

With

setlocal formatlistpat=^\s*\d\+[\]:.)}\t ]\s*\\\|^\\s*[-+*]\\s\\+
" instead of the default value formatlistpat=^\s*\d\+[\]:.)}\t ]\s*
setlocal formatoptions+=n

the second row is indented after the line break kicks in.

m1027

unread,
Aug 25, 2021, 10:37:10 AM8/25/21
to vim/vim, Subscribed

I am super happy that there is a solution already!

I am just stumbling accross an error when applying the formatlistpat. This happens even when I try to set the default pattern!

:set formatlistpat=^\s*\d\+[\]:.)}\t ]\s*
E518: Unknown option: ]\s

I am probably missing something trivial?
I am using neovim-4.4 (in case this matters).

Enno

unread,
Aug 25, 2021, 10:39:20 AM8/25/21
to vim/vim, Subscribed

I missed that everything needs to be doubly escaped. Correct should be

setlocal formatlistpat=^\s*\d\+[\]:.)}\t ]\s*\\\|^\\s*[-+*]\\s\\+

Yegappan Lakshmanan

unread,
Aug 25, 2021, 10:43:17 AM8/25/21
to vim_dev, reply+ACY5DGGTQTRIWDOLAI...@reply.github.com, vim/vim, Subscribed
Hi,

On Wed, Aug 25, 2021 at 4:08 AM m1027 <vim-dev...@256bit.org> wrote:

vim already detects a leading dash as bullet in txt files and can reformat a bullet list nicely (visual selection + gq).

But when actually typing in a long line, starting with a bullet (dash) and when the line break kicks in, the second row is indented as if there was no bullet.

Desired behaviour: When the line break kicks in, the next line should (optionally) start a little more to the right, just like gq does on paragraphs with leading dahes.


You can set the 'breakindentopt' and 'formatlistpat' options to  indent
bulleted lists as described above:

    set formatlistpat=^\\s*-\\s*
    set breakindent
    set breakindentopt=list:-1

The above assumes the bulleted lists start with a "-".

- Yegappan

vim-dev ML

unread,
Aug 25, 2021, 10:43:33 AM8/25/21
to vim/vim, vim-dev ML, Your activity

Hi,


On Wed, Aug 25, 2021 at 4:08 AM m1027 ***@***.***> wrote:

> vim already detects a leading dash as bullet in txt files and can reformat
> a bullet list nicely (visual selection + gq).
>
> But when actually *typing in* a long line, starting with a bullet (dash)

> and when the line break kicks in, the second row is indented as if there
> was no bullet.
>
> Desired behaviour: When the line break kicks in, the next line should
> (optionally) start a little more to the right, just like gq does on
> paragraphs with leading dahes.
>
>
> You can set the 'breakindentopt' and 'formatlistpat' options to indent
bulleted lists as described above:

set formatlistpat=^\\s*-\\s*
set breakindent
set breakindentopt=list:-1

The above assumes the bulleted lists start with a "-".

- Yegappan

m1027

unread,
Aug 26, 2021, 5:09:50 AM8/26/21
to vim/vim, vim-dev ML, Comment

First, thanks for all your ideas. So I am still convinced that it should work.

However, no success here.

See the code and my comments in between. I am opening vim /tmp/test.txt and
then do this:

:set formatoptions?
formatoptions=qjtn

:set formatlistpat?
formatlistpat=^\s*\d\+[\]:.)}\t ]\s*

(trying to apply that default, doubly escaped:)

:setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t ]\\s*
E518: Unknown option: ]\\s
(so, the doubly escaped default is not accepted?)

:setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}\\t]\\s*
(ok, no error when removing the single space, strange...)

(test: numbered bullets still indent 2nd line as expected)
(test: dash bullets obviously do not indent as desired yet)
(test: without bullets the second line indents like the first - ok)

:setlocal formatlistpat=^\\s*-\\s*
(ok, no error)

:set breakindent?
nobreakindent
:setlocal breakindent

:set breakindentopt?
breakindentopt=
:setlocal breakindentopt=list:-1
E474: Invalid argument: breakindentopt=list:-1

(test: numbered bullets do not indent anymore)
(test: dash bullets do not indent either)
(test: without bullets: regression, no indent at all, always column 1)

(trying the or'ed variant:)

:setlocal formatlistpat=^\s*\d\+[\]:.)}\t ]\s*\\\|^\\s*[-+*]\\s\\+
E518: Unknown option: ]\s*\\|^\\s*[-+*]\\s\\+

:setlocal formatlistpat=^\s*\d\+[\]:.)}\t]\s*\\\|^\\s*[-+*]\\s\\+
(ok, no error when removing the single space, strange...)

(test: numbered bullets do not indent anymore)
(test: dash bullets do not indent either)
(test: without bullets the second line indents like the first - ok)


You are receiving this because you commented.

Enno

unread,
Aug 26, 2021, 5:14:08 AM8/26/21
to vim/vim, vim-dev ML, Comment

Blanks need to be escaped, that is \ instead of . Did you try the setting at #8794 (comment) ?


You are receiving this because you commented.

m1027

unread,
Aug 26, 2021, 5:37:02 AM8/26/21
to vim/vim, vim-dev ML, Comment

Singly escaped blanks work, thanks.

When applying #8794 (comment) list/bullet indentation behaves like the default: Numbers work, dash doesn't.


You are receiving this because you commented.

Maxim Kim

unread,
Aug 26, 2021, 5:42:55 AM8/26/21
to vim/vim, vim-dev ML, Comment

bulleted lists as described above: set formatlistpat=^\s*-\s* set breakindent set breakindentopt=list:-1 The above assumes the bulleted lists start with a "-". - Yegappan

I doubt neovim4.4 has this new breakindentopt implemented.


You are receiving this because you commented.

Enno

unread,
Aug 26, 2021, 7:00:53 AM8/26/21
to vim/vim, vim-dev ML, Comment

I cannot reproduce: With Vim 8.0.1568 and vim --clean -u ~/.vim/viminrc where ~/.vim/viminrc reads

set formatlistpat=^\\s*\\d\\+[\\]:.)}\\t\ ]\\s*\\\|^\\s*[-+*]\\s\\+
set formatoptions+=n
set textwidth=68

the line following one starting with - ... is indented after the line break that kicks in after 68 characters.


You are receiving this because you commented.

m1027

unread,
Aug 26, 2021, 3:37:16 PM8/26/21
to vim/vim, vim-dev ML, Comment

Thanks again, your example via vim --clean indeed work here, using neovim-0.4.4.

So, there must be something else blocking indents for -, +, * in my case. I'll try to track that down.

Feel free to close this issue, if you prefer.


You are receiving this because you commented.

Enno

unread,
Aug 26, 2021, 4:21:07 PM8/26/21
to vim/vim, vim-dev ML, Comment

Possibly setting setlocal comments-=fb:- could help.


You are receiving this because you commented.

m1027

unread,
Aug 26, 2021, 4:53:25 PM8/26/21
to vim/vim, vim-dev ML, Comment

Closed #8794.


You are receiving this because you commented.

m1027

unread,
Aug 26, 2021, 4:53:26 PM8/26/21
to vim/vim, vim-dev ML, Comment

I've found out what was blocking your configuration in my case.

In my vimrc there is the global setting

set formatoptions=rqj

and then later, filetype related settings (for txt) get enabled by

au BufNewFile,BufRead,BufWinEnter *.txt	call FileTypeTXT()

where FileTypeTXT actually applies your proposed (usually working)
formatoptions etc via setlocal. This way I never had indentation for dashed
bullet lists.

I don't know what's wrong with this way of applying filetype based changes.
I am doing so for a long time now. It seems something gets mixed
up this way.

Anyway, I've found out that replacing the global setting

set formatoptions=rqj

with

set formatoptions+=rqj

helps. Thanks for the awesom help! Super happy to have dashed bullet list indentation now!


You are receiving this because you commented.

Reply all
Reply to author
Forward
0 new messages