VSCodeVim / VSCodeVim/Vim

Improve Pair Matching Logic to Skip Parentheses Inside Strings

Open
#9,344 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
15.2k
Forks
1.5k
Avg merge
3d 18h
Merged PRs (30d)
6

Description

Pair Matching Logic to Skip Parentheses Inside Strings

Issue Content
Description

In the current implementation of PairMatcher, the algorithm does not account for parentheses that may be located inside strings (e.g., "(')')"). This leads to incorrect jump behavior when users expect to skip parentheses within strings rather than treating them as matching pairs.

Steps to Reproduce
  1. In the editor, input a string such as: "(')')"
  2. Place the cursor on the first left parenthesis (.
  3. Use the % command to attempt to jump to the matching right parenthesis ).
Expected Behavior

The cursor should skip the right parenthesis inside the string and jump directly to the external matching right parenthesis.

Actual Behavior

The cursor incorrectly jumps to the right parenthesis inside the string.

Proposed Solution

I plan to add logic in the findPairedChar method to detect whether the current character is inside a string. Specifically, I will introduce a state variable to track whether we are inside a string and skip characters inside strings when processing parentheses. and make sure everything like ciw, ci" works fine

Related Code
  • findPairedChar method
  • PairMatcher class

Please feel free to let me know if you guys have any suggestions or thoughts.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the PairMatcher class and its findPairedChar method, then reproduce the reported case with "(')')" and the % command. Verify that matching skips parentheses inside strings while existing behaviors such as ciw and ci" continue to work; the issue is done when both the reported jump and those commands behave correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.