# helix: Fix \`Vim::NextWordEnd\` off-by-one in \`HelixSelect\` \(\#43234\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/5139cc2bfb6380ef0520727f2da57771018529e9)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 5139cc2bfb6380ef0520727f2da57771018529e9

Requested commit: 5139cc2bfb6380ef0520727f2da57771018529e9

Commit: 5139cc2bfb6380ef0520727f2da57771018529e9

Tree: 9c089e9021d2914856bcdd8446129510ac406fee

Author: AidanV

Committer: GitHub

## Message

```
helix: Fix `Vim::NextWordEnd` off-by-one in `HelixSelect` (#43234)

Closes #43209
Closes #38121

Starting on the first character.
Running `v e` before changes: 
<img width="410" height="162" alt="image"
src="https://github.com/user-attachments/assets/ee13fa29-826c-45c0-9ea0-a598cc8e781a"
/>

Running `v e` after changes:
<img width="483" height="166" alt="image"
src="https://github.com/user-attachments/assets/24791a07-97df-47cd-9ef2-171522adb796"
/>

Change Notes:

- Added helix selection sanitation code that directly mirrors the code
in the Vim
[`visual_motion`](https://github.com/AidanV/zed/blob/b6728c080c5d14ded7002d0276deb5c19d42ed8a/crates/vim/src/visual.rs#L237)
method. I kept the comments from the Vim section that explains its
purpose.
- The above change converted the problem from fixing `v e` to fixing `v
w`. Since `w` is treated differently in Helix than in Vim (i.e. `w` in
Vim goes to the first character of a word and `w` in Helix goes to the
character before a word. Commented
[here](https://github.com/AidanV/zed/blob/b6728c080c5d14ded7002d0276deb5c19d42ed8a/crates/vim/src/helix.rs#L132)),
the code treats `w` in `HelixSelect` as a motion that differs from the
Vim motion in the same way that the function
[`helix_move_cursor`](https://github.com/AidanV/zed/blob/b6728c080c5d14ded7002d0276deb5c19d42ed8a/crates/vim/src/helix.rs#L353)
separates these behaviors.
- Added a regression test

Release Notes:

- Fixes bug where `Vim::NextWordEnd` in `HelixSelect` would not select
whole word.
```

## Parents

- [c0e85481b09da81c852a7fc3f793a82fe125fe97](https://git.cafe/gitcafe/zed/commit/c0e85481b09da81c852a7fc3f793a82fe125fe97?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/5139cc2bfb6380ef0520727f2da57771018529e9?format=markdown)
