Skip to content

Fix w stepping over empty lines in vi mode - #135

Merged
ernestrc merged 2 commits into
unstablebuild:mainfrom
chiliec:fix-w-empty-line
Sep 30, 2026
Merged

ernestrc merged 2 commits into
unstablebuild:mainfrom
chiliec:fix-w-empty-line

Conversation

@chiliec

@chiliec chiliec commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #132

In Vim, w treats an empty line as a word. So w from the end of a line stops on the following empty line, and w on an empty line moves on to the next line. Rune's moveAfterRune skipped cells-less rows (cellAtCursor fails on them), so w/W jumped over empty lines, and returned early when the cursor already sat on one.

Changes:

  • moveAfterRune takes a stopAtEmptyLine flag. MoveRightStartWord / MoveRightStartWordGroup pass true; the backward ge/gE callers pass false, so their behaviour doesn't change. Whitespace-only lines are still skipped, as in Vim.
  • handleMetaNormal: with w now able to land on an empty line, the operator adjustment keeps dw/cw at the end of a line from eating the following empty line (one⏎⏎two, $dw → on⏎⏎two, matching the old behaviour and Vim). dw on an empty line deletes that line, as in Vim, where before it did nothing.

Tests: added TestViWordMotionEmptyLines (table-driven, 7 cases: $w, jw, $ww, $W, whitespace-only line, $dw, jdw).

Validation:

  • go test ./internal/text/vi/ -run TestViWordMotionEmptyLines: 5/7 cases fail on main, all pass with the fix
  • go test -race ./internal/text/...: all 12 packages pass
  • gofmt -l internal/: clean

Not run: make lint (golangci-lint isn't installed on my machine) and the e2e suites.

ernestrc
ernestrc previously approved these changes Sep 30, 2026
chiliec and others added 2 commits September 30, 2026 16:22
In Vim, w treats an empty line as a word, so it stops on it, and w on an empty
line moves on to the next line. Rune skipped empty lines entirely and did
nothing when the cursor was already on one. dw at the end of a line still stops
before the empty line, and dw on an empty line deletes it.

Signed-off-by: Vladimir Babin <[email protected]>
Counted dw/cw/yw from or across empty lines selected the wrong range, and cw on
an empty line joined it with the next. Follow Vim: the last word ends at its
line end, and an end in column 0 moves to the previous line, linewise from the
indent.

This also stops dfw/dtw from being treated as word motions, and pins the new
standard-mode Ctrl+Delete behavior at empty lines introduced by the word motion
change.

Signed-off-by: ernestrc <[email protected]>
@ernestrc
ernestrc merged commit 42d396c into unstablebuild:main Sep 30, 2026
7 of 8 checks passed
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.

Modal mode: next word on a blank line does not go to the next line

2 participants