You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vi: visual-block delete then paste only reinserts the last row #1
In vi mode, selecting a multi-line visual block with <c-v>, deleting it with d or x, and then pasting with p or P only reinserts the last row of the block. Vim pastes a block vertically: row N of the yanked block goes to row N below the cursor.
Yank-then-paste of a block already works. Only the delete-then-paste path is broken.
Steps to reproduce
Open a file with several lines in vi mode.
Press <c-v>, extend the selection down a few rows and right a few columns.
Press d.
Move the cursor elsewhere and press p.
Actual: a single line is inserted, containing only the last row of the deleted block. Expected: the whole block is reinserted vertically, one segment per line.
Root cause
Two writers touch the unnamed register during a visual-block delete. The vi handler first copies the full block (rows joined with \n, metadata BlockSelection), which is correct. The delete then runs one edit per row, and each row's edit notifies the delete-clipboard subscriber, which overwrites the register with just that row's text. After the loop the register holds only the last row, so paste inserts a single line.
Where to look
internal/text/delete_clipboard.go - the OnDidEdit subscriber that overwrites the register per row.
internal/text/vi/handler.go - copySelectionForDelete and the visual-mode d/x handler.
internal/cell/buffer.go - DeleteBlockContext, the per-row edit loop.
internal/text/cursor.go - Cursor.Paste / InsertBlock, which already handle blockwise pastes correctly when the register holds the joined text.
Notes for contributors
Per the bug-fix policy, start with a failing regression test. Table-driven cases worth covering: d then p, x then p, d then P, and a ragged block where rows have unequal length. The existing blockwise tests in internal/text/vi/handler_test.go are a good template. Make sure the black-hole register ("_d) behavior does not regress.
I'd like to take this. I confirmed the root cause: copySelectionForDelete (internal/text/vi/handler.go) writes the full block correctly, then DeleteSelection → DeleteBlockContext (internal/cell/buffer.go) fires one OnDidEdit per row and delClip (internal/text/delete_clipboard.go) overwrites the register each time, leaving only the last row.
Planned fix: in the visual-block d/x path, save the register data from copySelectionForDelete and re-assert it after DeleteSelection() (scoped to BlockSelection only, so char/line behavior is untouched). This also fixes "_d on blocks touching unnamed via delClip.
Regression tests (per bug-fix policy) at Vi integration level with WithCopyDelete installed handler-level tests bypass it covering d→p, x→p, d→P, a ragged block, and black-hole preservation.
Noted adjacent instances of the same pattern (c/s on block, visual-paste-replace, dot-repeat) I'll keep this PR to d/x unless you'd prefer them bundled. Let me know if the approach sounds good.
Activity
ikshantshukla123 commentedon Sep 12, 2026
I'd like to take this. I confirmed the root cause: copySelectionForDelete (internal/text/vi/handler.go) writes the full block correctly, then DeleteSelection → DeleteBlockContext (internal/cell/buffer.go) fires one OnDidEdit per row and delClip (internal/text/delete_clipboard.go) overwrites the register each time, leaving only the last row.
Planned fix: in the visual-block d/x path, save the register data from copySelectionForDelete and re-assert it after DeleteSelection() (scoped to BlockSelection only, so char/line behavior is untouched). This also fixes "_d on blocks touching unnamed via delClip.
Regression tests (per bug-fix policy) at Vi integration level with WithCopyDelete installed handler-level tests bypass it covering d→p, x→p, d→P, a ragged block, and black-hole preservation.
Noted adjacent instances of the same pattern (c/s on block, visual-paste-replace, dot-repeat) I'll keep this PR to d/x unless you'd prefer them bundled. Let me know if the approach sounds good.
Fix visual-block delete clobbering the unnamed register (#57)