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#
- Removed features in Neovim.
- Is the git binary diff algorithm (delta storage) standardized?
- https://vimways.org/2018/the-power-of-diff/ (it has some links on how indent-heuristic works)