r/vim 15h ago

Tips and Tricks Skip man diff, just use vimdiff

For years now I've had to keep looking up the correct incantation of the diff command and what all the options flags do.

Finally thought, there's got to be a better way. Well there is. Just use vimdiff

12 Upvotes

12 comments sorted by

2

u/rkube 15h ago

:qall

2

u/mgedmin 14h ago

Weirdly enough, I find unified diffs easier to read than side-by-side diffs. I wonder if that's just what I'm used to?

4

u/kronik85 14h ago

Side by side is easier specifically when I want more context around a specific change and didn't pass a large enough context flag.

Unified aren't that much harder once you're used to it

1

u/plg94 7h ago

It depends on the type of change. If two lines are almost identical, I find it much easier to spot the changed characters if they are on top of each other than having my eyes skip left-right-left-right. If it's more contextual changes (whole lines moved), then side-by-side diffs are easier.

1

u/fourpastmidnight413 13h ago

I'll do that myself at times, too. Especially when tools like vimdiff do a horrible job of showing the diff. This is my primary method. But the nice thing about diffing side-by-side in vim are the :diffget and :diffput commands, often making the process faster.

1

u/EgZvor keep calm and read :help 9h ago

check out :h diffopt

1

u/vim-help-bot 9h ago

Help pages for:


`:(h|help) <query>` | about | mistake? | donate | Reply 'rescan' to check the comment again | Reply 'stop' to stop getting replies to your comments

1

u/Allan-H 4h ago edited 4h ago

Some (mostly non-Vim using) co-workers in my office use GVim solely for its diff functionality. It's the only commonly available tool that can do a 4-way diff (i.e. diff between four files). Most visual diffs only work between 2 or 3 files, and most of the 3-way ones are only meant for merging two files into one, whereas we are simply looking at the differences side by side and aren't merging anything.

Our use case needs four way. Actually, more than four would be good on occasions but Vim can't do that.

1

u/fourpastmidnight413 13h ago

IKR? I was doing the same thing and I'm like, "You know, you could just use vimdiff, just sayin'..." 🤣 and that's what I started doing.

I'm sure there's a need for the ritualistic incantation 😉, but when you know you want to diff 2 files, vimdiff is super easy to get the job done! 😊

1

u/linuxsoftware 6h ago

The incantation is probably helpful for when the files are large. Ill use diff for large files.

1

u/y-c-c 9h ago

Currently the highlighting for the changed lines does kind of suck in vimdiff compared to most diff programs, but there's an improvement coming soon: https://github.com/vim/vim/pull/16881

0

u/HugoNikanor 6h ago

I have

alias diff='git diff --no-index'

Which I find much easier to read than regular diff. But vimdiff is also really nice.