# vim: Fix cursor position being set to end of line in normal mode \(\#38161\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 2759f541da451bd297ead1c1719126a807d336d1

Requested commit: 2759f541da451bd297ead1c1719126a807d336d1

Commit: 2759f541da451bd297ead1c1719126a807d336d1

Tree: 04f10cbf06948cda2e98a9191d047571522e5684

Author: Dino

Committer: GitHub

## Message

```
vim: Fix cursor position being set to end of line in normal mode (#38161)

Address an issue where, in Vim mode, clicking past the end of a line
after selecting the entire line would place the cursor on the newline
character instead of the last character of the line, which is
inconsistent with Vim's normal mode expectations.

I believe the root cause was that the cursor’s position was updated to
the end of the line before the mode switch from Visual to Normal, at
which point `DisplayMap.clip_at_line_ends` was still set to `false`. As
a result, the cursor could end up in an invalid position for Normal
mode. The fix ensures that when switching between these two modes, and
if the selection is empty, the selection point is properly clipped,
preventing the cursor from being placed past the end of the line.

Related #38049 

Release Notes:

- Fixed issue in Vim mode where switching from any mode to normal mode
could end up with the cursor in the newline character

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
```

## Parents

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

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