Skip to main content
  1. Posts/

Using Diffs in Vim

··235 words·2 mins·
Nvim Diff
Table of Contents

Diff can be used to compare two versions of the same file to find the changes. If you use vim, you can use vimdiff to compare files:

vimdiff file1 file2

Actually vimdiff is just a wrapper around vim executable, you can do the same thing with vim using option -d:

vim -d file1 file2

So neovim just removed this bloat. To compare two files using neovim, run:

nvim -d file1 file2

Previously, Vim has been using external diff tool for file diffs, since patch 8.1.0360, it beganto use libxdiff, which is much faster and has more features. According to discussion here, libxdiff is also used as a basis by Git as its internal diff library, that is when you use git diff inside a git repository.

Since this commit, the vim patch has been ported to neovim too. You can activate the internal diff algorithm by update option diffopt:

set diffopt+=internal

The default diff algorithm is myers diff. Other supported diff algorithm is:

                algorithm:{text} Use the specified diff algorithm with the
                internal diff engine. Currently supported
                algorithms are:
                myers      the default algorithm
                minimal    spend extra time to generate the
                           smallest possible diff
                patience   patience diff algorithm
                histogram  histogram diff algorithm

So to use histogram diff, add the following setting:

set diffopt+=algorithm:histogram

References
#

Related

Nifty Nvim/Vim Techniques That Make My Life Easier -- Series 9
··730 words·2 mins
Nvim Diff
Nifty Nvim/Vim Techniques That Make My Life Easier -- Series 8
··566 words·3 mins
Nvim Diff
Migrating from Packer.nvim to Lazy.nvim
··651 words·4 mins
Nvim Plugin