Skip to content

Conversation

@dinocosta
Copy link
Member

Update Vim's % motion to first attempt finding the exact matching bracket/tag under the cursor, then fall back to the previous nearest-enclosing logic if none is found. This prevents accidentally jumping to nested pairs in languages like TSX and Svelte where <>, </>, and /> are also treated as brackets.

Closes #39368

Release Notes:

  • Fixed an edge case with the % motion in vim, where the cursor could end up in a closing HTML tag instead of the matching bracket
This commit improves the `%` motion handling of nested brackets for
languages where `</>` are also valid brackets. With the previous
implementation, when `%` was used, Zed would try to find the innermost
bracket pair starting from the cursor position which, when the cursor is
positioned at the closing bracket, ends up returning the nested bracket
pair.

When this was the case, Zed would iterate over all available bracket
pairs and, if one of them started with `<` it would check if there's a
corresponding closing tag, and jump to that closing tag instead.

These changes simply check if any of the bracket ranges being processed
exactly match the cursor's offset in the buffer and, if so, it means
we're dealing with the actual bracket pair and should stop processing
and looking at other bracket pairs.
- Introduce new `new_tsx` test setup function - Add new test case to
test the issue with nested curly brackets and HTML tags when using the
`%` motion
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Oct 6, 2025
@dinocosta dinocosta merged commit 057b7b1 into main Oct 8, 2025
22 checks passed
@dinocosta dinocosta deleted the 39368-matching-motion branch October 8, 2025 12:49
LivioGama pushed a commit to LivioGama/zed that referenced this pull request Oct 11, 2025
Update Vim's `%` motion to first attempt finding the exact matching
bracket/tag under the cursor, then fall back to the previous
nearest-enclosing logic if none is found. This prevents accidentally
jumping to nested pairs in languages like TSX and Svelte where `<>`,
`</>`, and `/>` are also treated as brackets.

Closes zed-industries#39368 

Release Notes:

- Fixed an edge case with the `%` motion in vim, where the cursor could
end up in a closing HTML tag instead of the matching bracket
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

3 participants