[vim/vim] :diffget into an empty buffer creates an incorrect undo entry (Issue #20950)

Narendran Gopalakrishnan (Vim Github Repository) <[email protected]> Wed, 05 Aug 2026 03:55:09 -0700
Newsgroups gmane.editors.vim.devel
Message-ID <vim/vim/issues/[email protected]>

----==_mimepart_6a73168d6345e_100118017098
Content-Type: text/plain; charset="UTF-8"

gnarendran created an issue (vim/vim#20950)

### Steps to reproduce

### Reproducer
* Create two files, one empty and another with two lines "1" and "2":
printf "" > temp1.txt
printf "1\n2\n" > temp2.txt

* Then open vim in diff mode:
vi -u NONE -d temp1.txt temp2.txt
In the empty buffer temp1.txt type:

do
u

do makes them them identical (correct)
u (undo) leaves a residual last line "2" (wrong).

* The issue is reproduced with any number of lines, with undo always leaving the residual last line. Reproduced in nvim nightly and vim 9.2, indicating it is present in the common diff code.



### Expected behaviour

After :undo or normal u, the buffer should be restored to its original empty state.


### Version of Vim

In Vim 9.2.390; Also reproduced in Neovim nightly.

### Environment

Fedora 43
Reproduced in all $TERM (xterm-256color, or xterm-ktty) and in gvim as well.
bash

### Logs and stack traces

```shell

```

-- 
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/issues/20950
You are receiving this because you are subscribed to this thread.

Message ID: <vim/vim/issues/[email protected]>

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/vim/vim/issues/20950%40github.com.

----==_mimepart_6a73168d6345e_100118017098
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div style=3D"display: flex; flex-wrap: wrap; white-space: pre-wrap; align-=
items: center; "><img height=3D"20" width=3D"20" style=3D"border-radius:50%=
; margin-right: 4px;" decoding=3D"async" src=3D"https://avatars.githubuserc=
ontent.com/u/23692893" /><strong>gnarendran</strong> created an issue <a hr=
ef=3D"https://github.com/vim/vim/issues/20950">(vim/vim#20950)</a></div>
<h3 dir=3D"auto">Steps to reproduce</h3>
<h3 dir=3D"auto">Reproducer</h3>
<ul dir=3D"auto">
<li>
<p dir=3D"auto">Create two files, one empty and another with two lines "1" =
and "2":<br>
printf "" &gt; temp1.txt<br>
printf "1\n2\n" &gt; temp2.txt</p>
</li>
<li>
<p dir=3D"auto">Then open vim in diff mode:<br>
vi -u NONE -d temp1.txt temp2.txt<br>
In the empty buffer temp1.txt type:</p>
</li>
</ul>
<p dir=3D"auto">do<br>
u</p>
<p dir=3D"auto">do makes them them identical (correct)<br>
u (undo) leaves a residual last line "2" (wrong).</p>
<ul dir=3D"auto">
<li>The issue is reproduced with any number of lines, with undo always leav=
ing the residual last line. Reproduced in nvim nightly and vim 9.2, indicat=
ing it is present in the common diff code.</li>
</ul>
<h3 dir=3D"auto">Expected behaviour</h3>
<p dir=3D"auto">After :undo or normal u, the buffer should be restored to i=
ts original empty state.</p>
<h3 dir=3D"auto">Version of Vim</h3>
<p dir=3D"auto">In Vim 9.2.390; Also reproduced in Neovim nightly.</p>
<h3 dir=3D"auto">Environment</h3>
<p dir=3D"auto">Fedora 43<br>
Reproduced in all $TERM (xterm-256color, or xterm-ktty) and in gvim as well=
.<br>
bash</p>
<h3 dir=3D"auto">Logs and stack traces</h3>
<div class=3D"highlight highlight-source-shell" dir=3D"auto"><pre class=3D"=
notranslate"></pre></div>

<p style=3D"font-size:small;-webkit-text-size-adjust:none;color:#666;">&mda=
sh;<br />Reply to this email directly, <a href=3D"https://github.com/vim/vi=
m/issues/20950">view it on GitHub</a>, or <a href=3D"https://github.com/not=
ifications/unsubscribe-auth/ACY5DGH4SIIPQABALI7ZQFD5IMHA3AVCNFSNUABEKJSXA33=
TNF2G64TZHM2DAOJZG42DQMR3JFZXG5LFHM2TANZQGA4TGNZQGGQXMAQ">unsubscribe</a>.<=
br />Triage notifications, keep track of coding agent tasks and review pull=
 requests on the go with GitHub Mobile for <a href=3D"https://github.com/no=
tifications/mobile/ios/ACY5DGD6FSQUYN34AJBAB3T5IMHA3A5CNFSL4Z3JMQ5C6L3HNF2C=
22DVMIXUS43TOVSS6NJQG4YDAOJTG4YDDJTSMVQXG33OVJZXKYTTMNZGSYTFMSSWK5TFNZ2KUZT=
PN52GK4S7NFXXG">iOS</a> and <a href=3D"https://github.com/notifications/mob=
ile/android/ACY5DGHRGU2X37PJUWZJD3L5IMHA3A5CNFSL4Z3JMQ5C6L3HNF2C22DVMIXUS43=
TOVSS6NJQG4YDAOJTG4YDDJTSMVQXG33OVJZXKYTTMNZGSYTFMSSWK5TFNZ2K4ZTPN52GK4S7MF=
XGI4TPNFSA">Android</a>. Download it today!
<br />You are receiving this because you are subscribed to this thread.<img=
 src=3D"https://github.com/notifications/beacon/ACY5DGCKHNVLODYJPGYZUSD5IMH=
A3BFCNFSM6AAAAAC44PJIJKWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHQAA=
AAAEXDG7MFUZZGKYLTN5XKU43VMJZWG4TJMJSWI.gif" height=3D"1" width=3D"1" alt=
=3D"" /><span style=3D"color: transparent; font-size: 0; display: none; vis=
ibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-wid=
th: 0; max-height: 0; mso-hide: all">Message ID: <span>&lt;vim/vim/issues/2=
0950</span><span>@</span><span>github</span><span>.</span><span>com&gt;</sp=
an></span></p>

<script type=3D"application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/vim/vim/issues/20950",
"url": "https://github.com/vim/vim/issues/20950",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>

<p></p>

-- <br />
-- <br />
You received this message from the &quot;vim_dev&quot; maillist.<br />
Do not top-post! Type your reply below the text you are replying to.<br />
For more information, visit <a href=3D"http://www.vim.org/maillist.php">htt=
p://www.vim.org/maillist.php</a><br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;vim_dev&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">vim_dev+uns=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
vim_dev/vim/vim/issues/20950%40github.com?utm_medium=3Demail&utm_source=3Df=
ooter">https://groups.google.com/d/msgid/vim_dev/vim/vim/issues/20950%40git=
hub.com</a>.<br />

----==_mimepart_6a73168d6345e_100118017098--