How do you wrap text (via a highlighter) without preceding spaces?

When I’m working with plaintext files I frequently have long lines that I’d like to be visually wrapped. For this I do something like the following:

add-highlighter buffer/ wrap -word -width 50

However, that frequently results in lines that begin with whitespace as in the following example:

# Unwrapped
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec facilisis, massa in porta vehicula, nulla leo semper enim, in interdum quam nisi non erat.

# Wrapped (with the highlighter from above)
Lorem ipsum dolor sit amet, consectetur adipiscing
 elit. Donec facilisis, massa in porta vehicula,
nulla leo semper enim, in interdum quam nisi non
erat.

The second line starts with a space, which is really jarring. How can I make the highlighter swallow preceding whitespace?

And just to clarify: I am not interested in approaches that alter the source. I don’t want line-wrapped text in my files, just a visually wrapped representation.

That’s not currently possible.

Kakoune’s soft-wrapping can insert extra characters that cursor-movement skips (a line-break, an optional indent and an optional wrap-marker), but it cannot hide characters (like extra whitespace). The wrap-marker could be updated to leave the whitespace at the end of the previous line instead of wrapping it to the next, but people would be annoyed if a word that could fit on the previous line was wrapped just because it had a trailing whitespace character (or fifty) that pushed it over the limit.

It might be possible for the wrap highlighter to abbreviate wrapped whitespace in a similar way to how the replace-ranges highlighter works - if any selection ever overlaps part of the concealed text, it is revealed. However, I don’t know how invasive a change that would be to the codebase.

1 Like

Ah thanks for the extensive reply. It’s quite a shame that it’s not possible but at least I know now.

Do you know if there are any plans to make this possible in the future?

I don’t know of any plans to make that possible, no.

1 Like