PR: Set Correct '] Mark When Pasting Chunks
Twenty commits for a five-line fix: why explaining the reasoning behind a change matters as much as the change itself.
- neovim
- lua
- open-source
Background
I discovered this issue while browsing through the Neovim issue tracker.
Implementation Journey
The final fix was only a few lines of code, but the review process spanned 20+ commits.
Review Iterations
The review process was more challenging than the bug itself. After my initial implementation, @zeertzjq suggested improvements to the conditional logic. I experimented with various if branch arrangements, each time believing the code was close to ready.
When @zeertzjq brought @justinmk into the review, I was confident we were nearly done. But @justinmk proposed a different approach—one that, ironically, resembled my very first attempt. This sparked a cycle of toggling between versions, each making sense on its own but none winning consensus.
I eventually realized my mistake: I failed to document the rationale behind my implementation choices. Without explaining why I chose a particular approach, each reviewer naturally had their own preferences, creating unnecessary back-and-forth.
Final Implementation
Here is the merged version:
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -213,7 +213,7 @@ end
vim.inspect = vim.inspect
do
- local tdots, tick, got_line1, undo_started, trailing_nl = 0, 0, false, false, false
+ local startpos, tdots, tick, got_line1, undo_started, trailing_nl = nil, 0, 0, false, false, false
--- Paste handler, invoked by |nvim_paste()|.
---
@@ -328,7 +328,13 @@ do
-- message when there are zero dots.
vim.api.nvim_command(('echo "%s"'):format(dots))
end
+ if startpos == nil then
+ startpos = vim.fn.getpos("'[")
+ else
+ vim.fn.setpos("'[", startpos)
+ end
if is_last_chunk then
+ startpos = nil
vim.api.nvim_command('redraw' .. (tick > 1 and '|echo ""' or ''))
end
return true -- Paste will not continue if not returning `true`.
Key Takeaways
-
Document your reasoning: When multiple approaches are possible, explain why you chose yours. Reviewers can’t read your mind — a short rationale prevents misunderstandings and wasted iteration.
-
A small diff doesn’t mean a small effort: This PR’s final change was a few lines, but it took 20+ commits to get there. Don’t underestimate the social dimension of contributing to large projects.