Enable terminal reflow and join continuation lines in Normal mode#19863
Enable terminal reflow and join continuation lines in Normal mode#19863mattn wants to merge 11 commits intovim:masterfrom
Conversation
Enable vterm_screen_enable_reflow() so that long lines in a terminal window reflow (re-wrap) when the terminal is resized, instead of being truncated or leaving stale wrapped fragments. Fixes vim#2865
When switching to Terminal-Normal mode, use libvterm's VTermLineInfo continuation flag to join soft-wrapped lines into single buffer lines. This allows users to yank long lines (e.g. file paths) without embedded newlines, and makes :set number less wasteful of vertical space. Cursor position in Terminal-Normal mode is adjusted to account for the joined continuation lines.
The shell prompt varies across platforms (e.g. "sh-3.2$ " on macOS), so the reflowed line may not always be on row 2. Search all rows instead.
Also join continuation lines that are pushed into the scrollback buffer (lines scrolled off the top of the terminal screen), not just lines in the snapshot. This uses a new vterm_screen_sb_pushline_continuation() accessor that exposes the continuation flag of the line being pushed via the sb_pushline callback. Fix reflow tests to search all terminal rows instead of hardcoding row numbers, since shell prompts vary across platforms (e.g. macOS). Fix Test_term_getpos to account for joined continuation lines.
|
@Cimbali Thanks for testing! I just pushed a new commit that also joins continuation lines in the scrollback buffer (lines pushed off the top of the screen). This adds a |
|
I'll be looking for corner case bugs for a while, so it might not work for a short time. but I'll fix this soon. |
In state.c's scroll(), the lineinfo array is memmoved BEFORE the scrollrect callback fires, so by the time sb_pushline_from_row() runs, lineinfo[0] already holds the old row 1's info. Fix this by saving the continuation flag after each scroll for use on the NEXT push: after a scroll-by-1, lineinfo[0] tells whether the next row to be pushed will be a continuation. For resize pushlines, use new_lineinfo directly since it is built by the reflow process with correct continuation flags.
Wait for the job to become "dead" before reading exitval. Without this, the test can read exitval as 0 if the python process hasn't fully exited yet. Also fix the same issue in Test_terminal_duplicate_eof_arg.
Use 'printf '%s' ...' instead of 'printf '...'' to avoid relying on the shell's printf handling of UTF-8 characters directly in the format string, which may not work on FreeBSD.
Use 'echo -n' instead of 'printf '%s'' with single-quoted multibyte text. On macOS, /bin/sh (zsh) can break single quotes at multi-byte character boundaries.
Outputting CJK characters via shell commands is unreliable across platforms (macOS zsh, FreeBSD sh). The ASCII reflow tests and the normal-mode reflow test provide sufficient coverage.
febdb03 to
94f0775
Compare
On slower CI systems (FreeBSD), a single TermWait() may not be enough for printf output to appear. Use WaitForAssert() to wait for the expected output before checking the wrap or switching mode.
|
How does this differ from #8365 ? |
|
@chrisbra PR #8365 vs PR #19863 ComparisonBoth PRs fix the same issue #2865 — joining soft-wrapped (continuation) lines in the terminal buffer into single lines when switching to Normal mode. Approach Differences
#8365 Strengths and WeaknessesStrengths:
Weaknesses:
#19863 Strengths and WeaknessesStrengths:
Weaknesses:
Overall AssessmentFrom a practical standpoint, #19863 is attractive for its simplicity and reflow support. However, from an upstream compatibility standpoint, #8365 has a clear advantage since leonerd already implemented the Ideally, the best approach would be to use #8365's upstream-coordinated libvterm changes as the base and combine them with #19863's reflow enablement. chrisbra also asked in #19863 "How does this differ from #8365?", indicating that reconciliation between the two PRs is needed. |
|
Okay, then let's go with #8365 approach if this is also in libvterm already. |

Enable vterm_screen_enable_reflow() so that long lines in a terminal window reflow (re-wrap) when the terminal is resized. This function has been available in libvterm since patch 9.0.0774 (6a12d26) but was never called from Vim.
Additionally, when switching to Terminal-Normal mode, soft-wrapped (continuation) lines are now joined into single buffer lines using libvterm's VTermLineInfo continuation flag. This means:
:set numberno longer wastes vertical space on wrapped fragmentsFixes #2865
2026-03-30.214047.mp4
This PR was created with the assistance of Claude Code.