Re: vim diff - only display differences in lines

Yee Cheng Chin <[email protected]> Tue, 28 Oct 2025 18:10:13 -0700
Newsgroups gmane.editors.vim
Message-ID <CAHTeOx_6-cuNR5oMpjS6bYnch-SHaoF8mMtYq0QMp7rT1oTY0A@mail.gmail.com>
There isn't an easy way to sort the diff lines like so. Keep in mind that
Vim does not know or care that the user lines are "sorted" nor is it
immediately obvious to a diff algorithm how to do what you are showing
because it's very dependent on the user intent. All Vim sees from the diff
algorithm is "remove user2/user4 on the left, add user1/user3 on the
right". Generally diff algorithms do not care about whether the contents
are sorted or not.

Even if a feature is added to forcefully break the lines apart it would
look like this rather than what you want (keep in mind that this feature
does not exist and I simulated this by manually setting diff anchors):
[image: image.png]

Meanwhile if the inline highlight is distracting to you you can just turn
off inline diff (set diffopt+=inline:none), which at least prevents Vim
from doing the highlighting on the digits:
[image: image.png]

As I mentioned above, you can force Vim to show the diff however you want
with diff anchors. It's not automatic though, as diff anchors are more
designed to give you control over which lines to align where, when the
algorithm does not do what you want. Say if you *really *want it to show up
the way you want, with some manual fiddling to help visualize it, you can
do it and get it to show up like this (see :help diff-anchors to see how to
do this):

[image: image.png]

Diff anchor does have a bit of a learning curve especially if you need such
granular controls, and it isn't a good fit if you want everything to be
done automatically for you. FWIW the command I got to show the above is:

set diffopt+=anchor
setlocal diffanchors=1,2,2
setlocal diffanchors=2,2,3




On Tue, Oct 28, 2025 at 5:37 AM Igor <[email protected]> wrote:

> Hi,
> 1. I have two list of users like in file1:
> user1
> user3
>
> and in file2:
> user2
> user4
>
> 2. I open first file:
> :e file1
>
> 2. Open second file
> :vsp file2
>
> 3. Do the diff between files
> :windo diffthis
>
> Diff is displayed as differences between files:
> [image: 1.png]
>
> But I would like diff to be displayed as "line is missing" principle like
> this:
> [image: 2.png]
>
> Both list of users are sorted, so it should be visible which user is
> missing on which user list.
>
> How to force vim to display diff in "line missing" principle?
> Thanks
>
> --
> --
> You received this message from the "vim_use" 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_use" 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_use/ca29905e-da22-4bac-a8b2-ffe44ab4cb34n%40googlegroups.com
> <https://groups.google.com/d/msgid/vim_use/ca29905e-da22-4bac-a8b2-ffe44ab4cb34n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
-- 
You received this message from the "vim_use" 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_use" 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_use/CAHTeOx_6-cuNR5oMpjS6bYnch-SHaoF8mMtYq0QMp7rT1oTY0A%40mail.gmail.com.
2.png (image/png, 2 KB) - not displayed
1.png (image/png, 1.5 KB) - not displayed
image.png (image/png, 55.1 KB) - not displayed
image.png (image/png, 46.3 KB) - not displayed
image.png (image/png, 55.2 KB) - not displayed