5

Using Diffs in Vim

 2 years ago
source link: https://jdhao.github.io/2021/10/24/diff_in_vim/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Using Diffs in Vim

2021-10-24232 words 2 mins read spinner.svg times read

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

Author jdhao

LastMod 2021-10-24

License CC BY-NC-ND 4.0

Reward
Git Diff Setup

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK