Skip to content

Add softwrapcolumn option to soft-wrap at a fixed column#4142

Open
ddaanet wants to merge 1 commit into
micro-editor:masterfrom
ddaanet:softwrapcolumn
Open

Add softwrapcolumn option to soft-wrap at a fixed column#4142
ddaanet wants to merge 1 commit into
micro-editor:masterfrom
ddaanet:softwrapcolumn

Conversation

@ddaanet

@ddaanet ddaanet commented Jul 8, 2026

Copy link
Copy Markdown

Summary

When softwrap is enabled, lines wrap at the right edge of the pane. This adds a softwrapcolumn option that, when non-zero, wraps at that column instead — clamped to the pane width. It defaults to 0, which preserves today's behavior of wrapping at the pane edge, and only takes effect when softwrap is on.

This lets wrapped text line up with a fixed ruler (e.g. colorcolumn 80) regardless of how wide the pane happens to be.

Fixes #2374.

Design

  • Per-buffer common option, integer, default 0 (off). 0 = wrap at the pane edge (unchanged); N = wrap at column N. Same "off-sentinel" convention as other options.
  • Absolute column, clamped to pane width. When the configured column exceeds the pane width the wrap point falls back to the pane edge, so narrow panes degrade gracefully rather than wrapping off-screen. Matches the mental model of colorcolumn / scrollmargin.
  • Orthogonal to wordwrap. The wrap point becomes min(softwrapcolumn, bufWidth); the existing word-boundary logic is unchanged.
  • Continuation rows still start at column 0. This moves only the wrap threshold, not the loc↔visual mapping, so cursor/selection/mouse geometry stays linear per row (unlike the wrapindent approach in Add wrapindent option to allow wrapping and hanging indents #3107, which had to rewrite that mapping).

Implementation notes

The wrap width is tracked separately from the pane width (wrapWidth vs bufWidth), so the "dead zone" between the wrap column and the pane edge is still cleared on every visual row and keeps colorcolumn and cursor-line highlighting spanning the full pane.

Edge cases:

  • Column wider than the pane → clamped to the pane edge.
  • A word wider than the wrap column → hard-breaks at the column, mirroring baseline softwrap behavior at the pane edge.
  • Dead zone right of the column → cleared each row; colorcolumn and cursorline still draw across the full pane width.

Testing

make build and make test pass locally (go test ./internal/... ./cmd/...), including the
new softwrap_test.go cases.

When softwrap is enabled, lines wrap at the edge of the pane. This adds a
`softwrapcolumn` option that, when non-zero, wraps at that column instead,
clamped to the pane width. It defaults to 0, preserving the current
behavior of wrapping at the pane edge, and only takes effect when softwrap
is enabled.

The wrap width is tracked separately from the pane width (`wrapWidth` vs
`bufWidth`), so the region between the wrap column and the pane edge is
still cleared on every visual row and keeps colorcolumn and cursor-line
highlighting spanning the full pane.

Addresses micro-editor#2374.
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.

Option for setting length of lines

1 participant