vim/helix: Use grapheme count on replace#51776
Merged
dinocosta merged 4 commits intozed-industries:mainfrom Mar 25, 2026
Merged
vim/helix: Use grapheme count on replace#51776dinocosta merged 4 commits intozed-industries:mainfrom
dinocosta merged 4 commits intozed-industries:mainfrom
Conversation
Contributor
Have feedback on this plugin? Let's hear it! |
Update the current replace implementation for both vim and helix to take into account the grapheme count instead of the unicode scalar count. Using the unicode scalar count was already an improvement compared to what we had before, but it doesn't cover all scenarios, for example, when using some emoji, which although unlikely in source code, is a possibility and is currently correctly handled by Neovim. This commit introduces a new `multi_buffer::MultiBufferSnapshot::grapheme_count_for_range` method which returns the number of graphemes for a given range in the multibuffer, which then allows us to correctly determine the number of times the character being used for replace should repeat. Existing tests have also been updated with test cases that would fail without these new changes, to catch any potential regressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #51772
Multibyte characters are not handled properly with vim/helix replace, they replace based on bytes, instead of characters, so you will end up with too many new characters.
Vim Behavior Before:
Before_replace.mov
Vim Behavior After:
after.replace.mov
Helix Before:
helix.before.mov
Helix After:
helix.after.mov
I also added tests for the functionality.
Before you mark this PR as ready for review, make sure that you have:
Release Notes: