How to indent a soft wrapped line only for bullet lists in markdown

I want to use Kakoune to write markdown files, but find that the soft wrap around around bullet points makes them harder to read.

Current Behavior:

List:
- example bullet
point 1
- example bullet
point 2

This is is what i would want to happen:

List:
- example bullet
  point 1
- example bullet
  point 2

I have been struggling to achieve this behavior with soft wrapped lines, by probably misunderstanding how regional highlighters work. I also tried this by editing the markdown.kak directly and it would nice to know if this is the best way to do this.

You may be interested in the -indent and -marker xx options for the wrap highlighter.

The -indent option makes wrapped lines start at the same indent level as the first line, turning this:

Here is a list:

  - here is a list item that has an extreme
amount of text in it
  - yet another very long list item, you'd
think I have said everything already

…into this:

Here is a list:

  - here is a list item that has an extreme
  amount of text in it
  - yet another very long list item, you'd
  think I have said everything already

The -marker xx option inserts xx between the indent and the wrapped text. It’s often used to add a little icon to make it clear that the text is wrapped, like -marker ↪, but you can just set it to two spaces (-marker ' '), producing:

Here is a list:

  - here is a list item that has an extreme
    amount of text in it
  - yet another very long list item, you'd
    think I have said everything already

…which looks quite nice.

Of course, with Markdown you can use semantic line breaks even in list items, which I find works much more comfortably with editors like Kakoune.

1 Like

Thanks for the reply!

I tried this already but couldn’t quite figure out how to add this just for lists starting with a - or * and not just apply this to the whole buffer.

Yeah, it does apply to the whole buffer, but if the list-items require soft-wrapping, probably a lot of other things do too.

I think I need to formulate my question better.
How can i add the highlighter addhl wrap -word -indent -marker “ “ just when soft-wrapping lists and use addhl wrap -word -indent for everything else instead? (else longer paragraps look weird outside of lists) I tried looking at the markdown.kak, but didn’t understand how it uses regions.

After some trial and error I determined that the wrap highlighter doesn’t work correctly in a region or at least I think so.

This is the file i experimented on:

text

- list
- looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong list example that should have indents
- list

loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong paragraph that shouldn't have indents

This highlighter makes the lists work how i want them but breaks everything else:

add-highlighter global/softwrap wrap -word -indent -marker '  ' 
add-highlighter -override global/exampleRegion regions
add-highlighter -override global/exampleRegion/list region ^[*-]\s \S$ fill red
add-highlighter -override global/exampleRegion/listSoftwrap region ^[*-]\s \S$ wrap -word -indent -marker '  '

And this just doesn’t apply the -marker flag to the region i have defined:

add-highlighter global/softwrap wrap -word -indent
add-highlighter -override global/exampleRegion regions
add-highlighter -override global/exampleRegion/list region ^[*-]\s \S$ fill red
add-highlighter -override global/exampleRegion/listSoftwrap region ^[*-]\s \S$ wrap -word -indent -marker '  '

I dont’t have anything in my autoload directory that should interfere with this, so this really leaves me puzzled.

This makes sense. Kakoune (internally) groups highlighters into “passes”: “replace”, “wrap”, “move”, “colorize”. “replace” highlighters change the text that’s visible in the buffer, which you need to do before “wrap” highlighters lay the text out on screen. “Move” highlighters are things like line-numbering and flags, which need to know how many on-screen lines a line of the buffer occupies, so they have to run after “wrap” highlighters. Lastly, once all the other highlighters have moved text into its expected locations, “colorize” highlighters run to decide what colour the text should be.

wrap is (unsurprisingly) a “wrap” highlighter, and region is a “colorize” highlighter, so it’s probably impossible to set up a wrap highlighter that only applies to a specific region.