Skip to content

mac: vim gj/gk (and g0/g^/g$) move by visual rows, not logical lines - #238

Merged
GoKubar merged 1 commit into
mainfrom
agent/mac-vim-visual-rows
Sep 14, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/mac-vim-visual-rows

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Line wrapping defaults on, so a wrapped paragraph is one logical line spread over many screen rows. j moves a line, which means it leaps over the whole paragraph and the caret vanishes from where the user was looking. Vim's answer is gj/gk, and they were missing.

Motion gains visualDown/visualUp and rowStart/rowFirstNonBlank/rowEnd, resolved from the layout manager's line fragments rather than from the line table.

Details that matter

  • Separate remembered column. preferredVisualColumn is counted from the start of the visual row, independent of j/k's logical preferredColumn. Mixing the two does not make either drift.
  • Exclusive, as in Vim, so dgj removes up to the same column of the next row rather than two whole lines.
  • Counts and operators: 3gj, dgj, vgj. A count past the end stops on the last row instead of refusing to move.
  • The phantom final line. The empty line after a trailing newline has no glyphs, so the layout manager would answer with the row above it. j reaches that line, so these do too.
  • gj is j when nothing wraps — every visual row is then a logical line, so the user never has to think about which one to press.
  • No silent fall-back. No text view, no layout, or an empty buffer means "cannot move", never a quiet fall back to logical lines, which would move the caret somewhere the user did not ask for.

Also g0 / g^ / g$ — the ends of the visual row — since they are the natural companions and the same machinery.

Tests

10 new cases driven through the real editor view with a narrow monospaced text container so the sample paragraph genuinely wraps. The expected positions come from the layout's own line fragments, so the assertions check the motions against the layout rather than against hard-coded pixel guesses. One of them asserts the gap this closes directly: plain j leaves the paragraph, gj does not.

docs/user/gui.md updated.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

Line wrapping defaults on, so a wrapped paragraph is one logical line spread
over many screen rows. `j` moves a *line*, which means it leaps over the whole
paragraph — the caret vanishes from where the user was looking. Vim's answer is
`gj`/`gk`, and they were missing.

`Motion` gains `visualDown`/`visualUp` and `rowStart`/`rowFirstNonBlank`/
`rowEnd`, resolved from the layout manager's line fragments rather than from
the line table. Details that matter:

- They keep their own remembered column (`preferredVisualColumn`), separate
  from `j`/`k`'s. Mixing the two does not make either drift.
- Exclusive, as in Vim, so `dgj` removes up to the same column of the next row
  rather than two whole lines.
- Counts and operators work (`3gj`, `dgj`, `vgj`); a count past the end stops
  on the last row instead of refusing to move.
- The empty line after a trailing newline has no glyphs, so the layout manager
  would answer with the row above it. `j` reaches that line, so these do too.
- When nothing wraps, every visual row is a logical line and `gj` is exactly
  `j` — the user never has to think about which one to press.
- No text view, no layout, or an empty buffer means "cannot move", never a
  silent fall back to logical lines, which would move the caret somewhere the
  user did not ask for.

Tested through the real editor view with a narrow monospaced text container so
the sample paragraph genuinely wraps; the expected positions come from the
layout's own line fragments, so the assertions check the motions against the
layout rather than against hard-coded pixel guesses.

Implementation-Agent: claude-mac-lsp
Commit-Executor: claude-mac-lsp

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar
GoKubar marked this pull request as ready for review September 14, 2026 15:54
@GoKubar
GoKubar merged commit 421b07b into main Sep 14, 2026
19 of 20 checks passed
@GoKubar
GoKubar deleted the agent/mac-vim-visual-rows branch September 16, 2026 04:17
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