Skip to content

vim: Fix visual block handling of wrapped lines - #39355

Merged
yara-blue merged 1 commit into
mainfrom
vim-visual-block-wrapping-selection
Oct 3, 2025
Merged

vim: Fix visual block handling of wrapped lines#39355
yara-blue merged 1 commit into
mainfrom
vim-visual-block-wrapping-selection

Conversation

@dinocosta

Copy link
Copy Markdown
Member

These changes fix an issue with vim's visual block mode when soft wrapping is enabled. In this situation, if one was to move the cursor either up or down, the selection would be updated to include visual (wrapped) rows, instead of only the buffer rows. For example, take the following contents:

1 | And here's a very long line that is wrapping
    at this exact point.
2 | And another very long line that is will also
    wrap at this exact point.

If one was to place the cursor at the start of the first line, character A, trigger visual block mode with ctrl-v and then move down one line with j, the selection would end up as (with [X] representing the selected characters):

1 | [A]nd here's a very long line that is wrapping
    [a]t this exact point.
2 | [A]nd another very long line that is will also
    wrap at this exact point.

Instead of the expected:

1 | [A]nd here's a very long line that is wrapping
    at this exact point.
2 | [A]nd another very long line that is will also
    wrap at this exact point.

With the changes in this commit, Vim.visual_block_motion will now leverage buffer rows in order to navigate to the next or previous row.

Release Notes:

  • Fixed handling of soft wrapped lines in vim's visual block mode

This commit fixes an issue with vim's visual block mode when soft
wrapping is enabled. In this situation, if one was to move the cursor
either up or down, the selection would be updated to include visual
(wrapped) rows, instead of only the buffer rows. For example, take the
following contents:

```
1 | And here's a very long line that is wrapping
    at this exact point.
2 | And another very long line that is will also
    wrap at this exact point.
```

If one was to place the cursor at the start of the first line, character
`A`, trigger visual block mode with `ctrl-v` and then move down one line
with `j`, the selection would end up as (with [X] representing the
selected characters):

```
1 | [A]nd here's a very long line that is wrapping
    [a]t this exact point.
2 | [A]nd another very long line that is will also
    wrap at this exact point.
```

Instead of the expected:

```
1 | [A]nd here's a very long line that is wrapping
    at this exact point.
2 | [A]nd another very long line that is will also
    wrap at this exact point.
```

With the changes in this commit, `Vim.visual_block_motion` will now
leverage buffer rows in order to navigate to the next or previous row.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Oct 2, 2025
@dinocosta dinocosta changed the title fix(vim): fix visual block handling of wrapped lines vim: Fix visual block handling of wrapped lines Oct 2, 2025
@dinocosta

Copy link
Copy Markdown
Member Author

Here's a screen recording of the before and after ↓

Before

before.mp4

After

after.mp4

cc @dvdsk 👀

@yara-blue yara-blue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! LGTM 🎉

@yara-blue
yara-blue merged commit 8441aa4 into main Oct 3, 2025
24 checks passed
@yara-blue
yara-blue deleted the vim-visual-block-wrapping-selection branch October 3, 2025 13:58
dinocosta added a commit that referenced this pull request Oct 21, 2025
The `vim::visual::Vim.visual_block_motion` method was recently updated
(#39355) in order to jump
between buffer rows instead of display rows. However, with this now
being the case, the `break` condition was never met when the motion was
horizontal rather than vertical and soft wrapped lines were used. As
such, this commit udpates the condition to ensure it's always reached,
preventing the hanging from happening.

Release Notes:

- Fixed hang in Vim's visual block motions when updating selections

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
dinocosta added a commit that referenced this pull request Oct 21, 2025
The `vim::visual::Vim.visual_block_motion` method was recently updated
(#39355) in order to jump
between buffer rows instead of display rows. However, with this now
being the case, the `break` condition was never met when the motion was
horizontal rather than vertical and soft wrapped lines were used. As
such, this commit udpates the condition to ensure it's always reached,
preventing the hanging from happening.

Release Notes:

- Fixed hang in Vim's visual block motions when updating selections

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
jasonsmithio pushed a commit to paddleboarddev/paddleboard that referenced this pull request May 31, 2026
The `vim::visual::Vim.visual_block_motion` method was recently updated
(zed-industries/zed#39355) in order to jump
between buffer rows instead of display rows. However, with this now
being the case, the `break` condition was never met when the motion was
horizontal rather than vertical and soft wrapped lines were used. As
such, this commit udpates the condition to ensure it's always reached,
preventing the hanging from happening.

Release Notes:

- Fixed hang in Vim's visual block motions when updating selections

---------

Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
These changes fix an issue with vim's visual block mode when soft
wrapping is enabled. In this situation, if one was to move the cursor
either up or down, the selection would be updated to include visual
(wrapped) rows, instead of only the buffer rows. For example, take the
following contents:

```
1 | And here's a very long line that is wrapping
    at this exact point.
2 | And another very long line that is will also
    wrap at this exact point.
```

If one was to place the cursor at the start of the first line, character
`A`, trigger visual block mode with `ctrl-v` and then move down one line
with `j`, the selection would end up as (with [X] representing the
selected characters):

```
1 | [A]nd here's a very long line that is wrapping
    [a]t this exact point.
2 | [A]nd another very long line that is will also
    wrap at this exact point.
```

Instead of the expected:

```
1 | [A]nd here's a very long line that is wrapping
    at this exact point.
2 | [A]nd another very long line that is will also
    wrap at this exact point.
```

With the changes in this commit, `Vim.visual_block_motion` will now
leverage buffer rows in order to navigate to the next or previous row.

Release Notes:

- Fixed handling of soft wrapped lines in vim's visual block mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants