Skip to content

For discussion: Add optional hard wrapping on input (editor.hard-wrap) - #16373

Open
gwicke wants to merge 1 commit into
helix-editor:masterfrom
gwicke:feature/hard-wrap
Open

gwicke wants to merge 1 commit into
helix-editor:masterfrom
gwicke:feature/hard-wrap

Conversation

@gwicke

@gwicke gwicke commented Oct 10, 2026

Copy link
Copy Markdown

For-discussion implementation of #2274. Functional and working well for me, but NOT ready for merge yet. I am looking for feedback first, and there are some documented deferred / backlog items in the temporary design doc. To test, build hx with this patch, and add the following section to your config.toml:

[editor.hard-wrap]
enable = true

Implement hard wrap at input time, similar to vim's textwidth: when a non-whitespace character is entered past text-width, the affected line is broken at its softwrap wrap point and continues on the next line with the line's indentation, list marker (aligned under the item content, never a repeated marker) and comment token re-applied. Words are never split; a word too long to fit overflows until a space is entered past it. Only lines being edited are touched, and soft wrapping remains an independent display transform.

The break point is computed by reusing the softwrap traversal (DocumentFormatter) with the width budget reduced on continuation rows for the continuation prefix, so the wrap points match what softwrap would display. The continuation-prefix resolver floors the line's leading whitespace, raises it to the tree-sitter indent when available, then appends the comment token (reusing continue-comments detection) and a list-marker delta. enable and list-markers are resolved per position through the innermost language layer (following injections), then the document language, then the global config. List-marker detection is configurable via the auto-pairs-style [editor.hard-wrap].list-markers option (bool or custom regex).

The wrap applies as a second transaction composing into the same pending changeset as the insert, keeping a single undo step. Paste, completion/snippet inserts and Enter are intentionally unchanged.

See docs/261010_hard_wrap.md for the full design.

Implement hard wrap at input time, similar to vim's textwidth: when a
non-whitespace character is entered past text-width, the affected line is
broken at its softwrap wrap point and continues on the next line with the
line's indentation, list marker (aligned under the item content, never a
repeated marker) and comment token re-applied. Words are never split; a
word too long to fit overflows until a space is entered past it. Only
lines being edited are touched, and soft wrapping remains an independent
display transform.

The break point is computed by reusing the softwrap traversal
(DocumentFormatter) with the width budget reduced on continuation rows
for the continuation prefix, so the wrap points match what softwrap
would display. The continuation-prefix resolver floors the line's
leading whitespace, raises it to the tree-sitter indent when available,
then appends the comment token (reusing continue-comments detection)
and a list-marker delta. `enable` and `list-markers` are resolved per
position through the innermost language layer (following injections),
then the document language, then the global config. List-marker detection
is configurable via the auto-pairs-style [editor.hard-wrap].list-markers
option (bool or custom regex).

The wrap applies as a second transaction composing into the same
pending changeset as the insert, keeping a single undo step. Paste,
completion/snippet inserts and Enter are intentionally unchanged.

See docs/261010_hard_wrap.md for the full design.
@gwicke
gwicke force-pushed the feature/hard-wrap branch from 49be4b6 to 6d9e946 Compare October 10, 2026 22:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant