# Fix duplicate prefixes when repeating completions in Vim mode \(\#31818\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/e0b818af6236455ab22db1a11645a95ea0995d98)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: e0b818af6236455ab22db1a11645a95ea0995d98

Requested commit: e0b818af6236455ab22db1a11645a95ea0995d98

Commit: e0b818af6236455ab22db1a11645a95ea0995d98

Tree: fb8c079411e35b3e6839d702e3d69c0b62672690

Author: Arseny Kapoulkine

Committer: GitHub

## Message

````
Fix duplicate prefixes when repeating completions in Vim mode (#31818)

When text is completed, new_text contains the entire new completion
which replaces the old_text. In Vim mode, pressing . repeats the
completion; if InputHandled records the full text and no range to
replace, the entire completion gets appended; this happens after the
completion prefix typing repeats, and we get a duplicate prefix.

Using range to replace has some downsides when the completion is
repeated as a standalone action; in a common case, it should be
sufficient to record the new suffix. This is actually what used to
happen before #28586, which removed this code in a larger attempt to fix
completions at multiple cursors:

```rust
let text = &new_text[common_prefix_len..];
let utf16_range_to_replace = ...

cx.emit(EditorEvent::InputHandled {
    utf16_range_to_replace,
    text: text.into(),
});
```

Fixes #30758
Fixes #31759
Fixes #31779

Release Notes:

- Vim: Fix duplicate prefixes when repeating completions via `.`
````

## Parents

- [58a400b1eec67405c2f0521585a9ab4c277b6ee8](https://git.cafe/gitcafe/zed/commit/58a400b1eec67405c2f0521585a9ab4c277b6ee8?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/e0b818af6236455ab22db1a11645a95ea0995d98?format=markdown)
