Skip to content

vim: Ensure paragraph motions use empty and not blank lines - #47734

Merged
dinocosta merged 2 commits into
zed-industries:mainfrom
lex00:fix/36171-vim-paragraph-whitespace
Jan 27, 2026
Merged

vim: Ensure paragraph motions use empty and not blank lines#47734
dinocosta merged 2 commits into
zed-industries:mainfrom
lex00:fix/36171-vim-paragraph-whitespace

Conversation

@lex00

@lex00 lex00 commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #36171

The } and { paragraph motions now correctly treat only truly empty lines (zero characters) as paragraph boundaries, matching vim's documented behavior. Whitespace-only lines are no longer treated as boundaries.

The problem

In vim mode, pressing } would stop at lines containing only whitespace (spaces, tabs). According to vim's :help paragraph:

A paragraph begins after each empty line

An "empty" line in vim terminology has zero characters, not whitespace-only.

The fix

Changed start_of_paragraph() and end_of_paragraph() in editor/src/movement.rs to check line_len() == 0 instead of is_line_blank().

Note: This change does NOT affect the ap/ip text objects. Per vim's :help ap, those DO treat whitespace-only lines as boundaries, which is the existing (correct) behavior in vim/src/object.rs.

Test plan

  • Added test_paragraph_motion_with_whitespace_lines using NeovimBackedTestContext
  • Existing test_start_end_of_paragraph still passes

Release Notes:

  • Fixed vim mode paragraph motions (} and {) to correctly ignore whitespace-only lines

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jan 27, 2026
@MrSubidubi MrSubidubi changed the title Vim paragraph motions should use empty lines, not blank lines vim: Ensure paragraph motions use empty and not blank lines Jan 27, 2026

@dinocosta dinocosta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @lex00 ! I've pushed a small commit updating the test you added (thanks!) to leverage our NeoVim backed tests, that way we can ensure that this matches NeoVim's behavior too ✌️

@dinocosta
dinocosta enabled auto-merge (squash) January 27, 2026 13:28
@dinocosta
dinocosta merged commit 9ecafe1 into zed-industries:main Jan 27, 2026
27 checks passed
@aviatesk

Copy link
Copy Markdown
Collaborator

Although I understand the intent to match vim's documented behavior for { and } motions, I'd like to point out that this change affects the general editor actions (MoveToStartOfParagraph / MoveToEndOfParagraph), not just vim mode.
For vim users, this is indeed a fix, but for users who don't use vim mode (like myself), this is a breaking change. The previous behavior of treating whitespace-only lines as paragraph boundaries was useful for navigating code blocks separated by indented blank lines.

It's also worth noting that even within the vim community, this behavior has been vim/vim#222, with plugins like
https://github.com/dbakker/vim-paragraph-motion existing specifically to restore the "blank line as boundary" behavior.

Would it be possible to either:

  1. Apply this stricter "empty line only" behavior exclusively within vim mode, or
  2. Make this configurable via a setting?

This would preserve vim compatibility for those who need it while avoiding regression for other users.

@lex00

lex00 commented Jan 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for pointing this out—you're right, I should have considered non-vim users. I've opened #48024 which applies the stricter behavior only in vim mode, per your first suggestion.

dinocosta added a commit that referenced this pull request Feb 17, 2026
Reverts the editor's paragraph navigation behavior that was changed in
#47734. Whitespace-only lines are now treated as paragraph boundaries
again for non-vim mode users.

Vim mode retains its own implementation where only truly empty lines
are paragraph boundaries.

Release Notes:

- Fixed editor paragraph navigation to treat whitespace-only lines as
paragraph boundaries again

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
rtfeldman pushed a commit that referenced this pull request Feb 17, 2026
Reverts the editor's paragraph navigation behavior that was changed in
#47734. Whitespace-only lines are now treated as paragraph boundaries
again for non-vim mode users.

Vim mode retains its own implementation where only truly empty lines
are paragraph boundaries.

Release Notes:

- Fixed editor paragraph navigation to treat whitespace-only lines as
paragraph boundaries again

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
@lex00
lex00 deleted the fix/36171-vim-paragraph-whitespace branch March 1, 2026 20:21
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
…stries#47734)

The `}` and `{` paragraph motions now correctly treat only truly empty
lines (zero characters) as paragraph boundaries, matching vim's
documented behavior. Whitespace-only lines are no longer treated as
boundaries.

Changed `start_of_paragraph()` and `end_of_paragraph()` in
`editor/src/movement.rs` to check `line_len() == 0` instead of
`is_line_blank()`.

Note: This change does NOT affect the `ap`/`ip` text objects. Per vim's
`:help ap`, those DO treat whitespace-only lines as boundaries, which is
the existing (correct) behavior in `vim/src/object.rs`.

Closes zed-industries#36171

Release Notes:

- Fixed vim mode paragraph motions (`}` and `{`) to correctly ignore
whitespace-only lines

---------

Co-authored-by: dino <dinojoaocosta@gmail.com>
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
…8024)

Reverts the editor's paragraph navigation behavior that was changed in
zed-industries#47734. Whitespace-only lines are now treated as paragraph boundaries
again for non-vim mode users.

Vim mode retains its own implementation where only truly empty lines
are paragraph boundaries.

Release Notes:

- Fixed editor paragraph navigation to treat whitespace-only lines as
paragraph boundaries again

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…stries#47734)

The `}` and `{` paragraph motions now correctly treat only truly empty
lines (zero characters) as paragraph boundaries, matching vim's
documented behavior. Whitespace-only lines are no longer treated as
boundaries.

Changed `start_of_paragraph()` and `end_of_paragraph()` in
`editor/src/movement.rs` to check `line_len() == 0` instead of
`is_line_blank()`.

Note: This change does NOT affect the `ap`/`ip` text objects. Per vim's
`:help ap`, those DO treat whitespace-only lines as boundaries, which is
the existing (correct) behavior in `vim/src/object.rs`.

Closes zed-industries#36171

Release Notes:

- Fixed vim mode paragraph motions (`}` and `{`) to correctly ignore
whitespace-only lines

---------

Co-authored-by: dino <dinojoaocosta@gmail.com>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…8024)

Reverts the editor's paragraph navigation behavior that was changed in
zed-industries#47734. Whitespace-only lines are now treated as paragraph boundaries
again for non-vim mode users.

Vim mode retains its own implementation where only truly empty lines
are paragraph boundaries.

Release Notes:

- Fixed editor paragraph navigation to treat whitespace-only lines as
paragraph boundaries again

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
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.

vim-mode: Paragraph object incorrectly treats whitespace-only lines as boundaries

3 participants