# vim: Fix paste crash with out-of-order marks \(\#64876\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 2280e5d95e777c942733e14778b4adf69b126895

Requested commit: 2280e5d95e777c942733e14778b4adf69b126895

Commit: 2280e5d95e777c942733e14778b4adf69b126895

Tree: 29d251ce3e092735bbf213a89a36396886511e42

Author: Agus Zubiaga

Committer: GitHub

## Message

```
vim: Fix paste crash with out-of-order marks (#64876)

## Summary

Pasting multiple selections at the end of a file could crash Vim while
saving paste marks, because their anchors are not necessarily in
document order. Serialize those marks with a summarizer that reuses its
cursors while moving forward and resets them when an anchor moves
backward, preserving mark order.

Fixes
[FR-506](https://linear.app/zed-industries/issue/FR-506/zed-c22-cannot-summarize-backward-from-26-to-23).

## Testing

In Vim mode, copy `abcdef` and `xyz` as two separate selections in Zed.
Open a saved file containing `012345678901234567890` with no trailing
newline, put one cursor on the final `0`, and press `p`. The paste
should complete without crashing.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [ ] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist) (not
applicable).
- [x] Tests cover the new or changed behavior.

Release Notes:

- Fixed a crash when pasting multiple selections at the end of a file in
Vim mode.
```

## Parents

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

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