Skip to content

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

Merged
dinocosta merged 2 commits intozed-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 intozed-industries:mainfrom
lex00:fix/36171-vim-paragraph-whitespace

Conversation

@lex00
Copy link
Contributor

@lex00 lex00 commented Jan 27, 2026

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
@lex00 lex00 force-pushed the fix/36171-vim-paragraph-whitespace branch from 3facde2 to c2b7188 Compare January 27, 2026 08:11
Copy link
Member

@dinocosta dinocosta left a comment

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
Contributor

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 added a commit to lex00/zed that referenced this pull request Jan 30, 2026
Addresses feedback from zed-industries#47734: the previous change affected all users,
but the stricter "empty line only" paragraph behavior (per vim's :help
paragraph) should only apply in vim mode.

- Revert editor's paragraph functions to use is_line_blank() (whitespace
  lines count as boundaries for non-vim users)
- Add vim-specific paragraph_backwards/paragraph_forwards that use
  line_len() == 0 (only truly empty lines are boundaries)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@lex00
Copy link
Contributor Author

lex00 commented Jan 30, 2026

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.

lex00 added a commit to lex00/zed that referenced this pull request Feb 4, 2026
Addresses feedback from zed-industries#47734: the previous change affected all users,
but the stricter "empty line only" paragraph behavior (per vim's :help
paragraph) should only apply in vim mode.

- Revert editor's paragraph functions to use is_line_blank() (whitespace
  lines count as boundaries for non-vim users)
- Add vim-specific paragraph_backwards/paragraph_forwards that use
  line_len() == 0 (only truly empty lines are boundaries)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
lex00 added a commit to lex00/zed that referenced this pull request Feb 13, 2026
Addresses feedback from zed-industries#47734: the previous change affected all users,
but the stricter "empty line only" paragraph behavior (per vim's :help
paragraph) should only apply in vim mode.

- Revert editor's paragraph functions to use is_line_blank() (whitespace
  lines count as boundaries for non-vim users)
- Add vim-specific paragraph_backwards/paragraph_forwards that use
  line_len() == 0 (only truly empty lines are boundaries)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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
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